semaphore

RuntimeWarning: Enable tracemalloc to get the object allocation traceback with asyncio.sleep

三世轮回 提交于 2021-02-04 12:07:57
问题 Trying to use a semaphore to control asynchronous requests to control the requests to my target host but I am getting the following error which I have assume means that my asycio.sleep() is not actually sleeping. How can I fix this? I want to add a delay to my requests for each URL targeted. Error: RuntimeWarning: coroutine 'sleep' was never awaited Coroutine created at (most recent call last) File "sephora_scraper.py", line 71, in <module> loop.run_until_complete(main()) File "/Library

POSIX semaphores - cannot determine what causes segmentation fault

若如初见. 提交于 2021-01-29 19:54:19
问题 I'm working on the sleeping barber problem (using FIFO queue and shared memory), and I have a problem. I try to run this program just to see what is shown, however, I get segmentation fault every time. In the code I check, if semaphores are created successfully, if shared memory is created properly, but the program crashing must come from different place, which I cannot seem to find. I also tried to use Valgrind but what I got is: Valgrind for the newer version of code: However, when I try to

Java- Allow one thread to update a value, others to wait and skip critical section

不羁岁月 提交于 2021-01-29 18:01:21
问题 Hi I have a situation in which I have to allow only one thread to say update a variable. There is a trigger, which might invoke multiple threads to update this variable, however the update should happen only once by the first thread whichever arrives at the critical section. Ideally the flow should be like follows: Thread-1; Thread-2 and Thread-3 are invoked to update a variable in critical section guarded by a lock or a mutex Critical section using this guard allows only one thread to enter,

C# Semaphores not working as expected, cannot figure out why

三世轮回 提交于 2021-01-29 05:43:56
问题 I am building an ASP.NET (.NET Framework) application in C# I am making API calls to a backend service called "LinuxDocker" and I am trying to limit the number of 12 concurrent calls to it from the ASP.NET application. Here is the code I wrote: private static Semaphore LinuxDockerSemaphore = new Semaphore(12, 12); public static SemaphoreWaiter WaitForLinuxDocker(int timeoutMS = -1) { return new SemaphoreWaiter(LinuxDockerSemaphore, timeoutMS); } public class SemaphoreWaiter : IDisposable {

.Net Core Async critical section if working on same entity

你说的曾经没有我的故事 提交于 2021-01-27 17:51:29
问题 I need to be sure that a method accessed via a web API cannot be accessed by multiple call at the same time if it work on the same object with the same id I understand the use of SemaphoreSlim but a simple implemetation of that will lock the critical section for all. But I need that section locked only if it works on the same entity and not on 2 different This is my scenario, an user start to work, the entity is created and is ready to be modified, then one or more user can manipulate this

Max values of semaphore?

只愿长相守 提交于 2021-01-01 06:49:08
问题 For example, there is a 1000 times loop. What's the max value to make it fast, effective, and not lead to a deadlock? let group = DispatchGroup() let queue = DispatchQueue(label: "com.num.loop", attributes: .concurrent) let semaphore = DispatchSemaphore(value: 4) for i in 1...1000 { semaphore.wait() group.enter() queue.async(group: group, execute: { doWork(i) group.leave() semaphore.signal() }) } group.notify(queue: DispatchQueue.main) { // go on... } 回答1: A couple of observations: You never

Max values of semaphore?

こ雲淡風輕ζ 提交于 2021-01-01 06:48:27
问题 For example, there is a 1000 times loop. What's the max value to make it fast, effective, and not lead to a deadlock? let group = DispatchGroup() let queue = DispatchQueue(label: "com.num.loop", attributes: .concurrent) let semaphore = DispatchSemaphore(value: 4) for i in 1...1000 { semaphore.wait() group.enter() queue.async(group: group, execute: { doWork(i) group.leave() semaphore.signal() }) } group.notify(queue: DispatchQueue.main) { // go on... } 回答1: A couple of observations: You never

DispatchQueue threads don't always set the correct results

别等时光非礼了梦想. 提交于 2020-12-13 03:09:07
问题 Am trying on coding game MineSweeper, the following code is to set the numbers around landmines. For a test, I choose the minimum level 9 x 9 with 10 landmines. For a faster performance, I tried to use more threads when setting numbers, but one day I found that it doesn't always give the correct number arrangements, I made a loop to create it 1000 times and found that 20 ~ 40 out of 1000 are wrong. Here are several wrong results, "*" represents landmine, "0" means no landmine around wrong