Reputation: 149
I am trying to use an event (manual reset) to signal that a file change has been made. I have a scenario where thread A calls SetEvent and Thread B and C are checking if the event has been signaled. When B or C detect that the event has been signaled they reset the event and do some work. My question is when thread B resets the event will thread C still register that the event was signaled?
Upvotes: 1
Views: 213
Reputation: 37192
Windows doesn't maintain per-thread event states. An event is either signaled or not, and all threads will see the same state.
If you have two threads waiting on the one event, and both threads reset that event once it is signaled, you run the risk of one thread not seeing the signal at all (because the other thread has already reset it).
You would need a synchronization mechanism so that the event is only reset once all threads that are checking it have seen the new state (for example, an atomic counter that each thread decrements, and the event only gets reset when it reaches 0).
Depending on your application, a semaphore may be more suitable.
Upvotes: 3