Is it safe to have 2 or more threads call the Win32 API's SetEvent on the same event handler not being protected by a critical section?
A:
Assuming you have multiple threads waiting on the same event, running the same code.
- If your code doesnt clear the event until its done processing, you effectively have a CS. Since the event remains signaled until it is cleared(aka not autoreset), having multiple threads signal the does nothing except spin the CPU.
- If your code clears it at the begining of processing or the event is autorset, then you would have multiple threads running the same function, which is unsafe if these threads share anything.
Sanjaya R
2008-11-05 14:03:40
+1
A:
It's safe, but remember that if one thread Sets it, and another thread Sets it at the same time, you're not going to get two notifications, just one; since the 2nd one changed it from True to...True. If you're worried about this, use Semaphores instead.
Paul Betts
2009-05-26 17:57:48