Search code examples
multithreadingwinapieventsatomiccritical-section

Is SetEvent atomic?


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?


Solution

  • 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.