I have a game server than can take requests from a user. A user can request to place pieces. The place method then spawns some async httpwebrequests (with timeouts) to find out if the placement was correct. I want a lock that will be locked when the server receives the placement request, and will be unlocked by the web callback. I would use a ReaderWriterLock, but that only works if I stay in the same thread, and the web request callbacks occur on different threads. Is there another lock I should use?
You can use a semaphore. The locking thread acquires a permit. The async thread releases a permit. Semaphores are nifty because they aren't bound to individual threads.
You could use a Semaphore. Quote from the manual;
The Semaphore class does not enforce thread identity on calls to WaitOne or Release.
In other words, you should not have a problem acquiring/releasing from two different threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With