Block in one thread, release in another

I have a game server that can accept requests from the user. User can request placement of items. The location method then spawns some asynchronous httpwebrequests (with timeouts) to find out if the placement is set correctly. I want a lock that will be locked when the server receives a hosting request and is unlocked by a web callback. I would use ReaderWriterLock, but this only works if I stay in the same thread and web request callbacks occur in different threads. Is there another lock I should use?

+6
source share
2 answers

You can use a semaphore . Locking thread gets permission. Asynchronous thread releases permission. Semaphores are great because they are not related to individual threads.

+9
source

You can use Semaphore . Quote from the manual;

The Semaphore class does not provide thread identification for WaitOne or Release calls.

In other words, you should not have problems getting / releasing from two different streams.

+4
source

Source: https://habr.com/ru/post/907888/


All Articles