Reputation: 2691
I have an auto-reset event object, and there is one thread waiting on it. If now I call SetEvent, can it be guaranteed that the event object is nonsignaled when SetEvent has returned?
I have two threads that run in a A-B-A-B-... way. As soon as A wakes up B, A will start waiting for B. If I can wait on the same event object right after signaled it, well... I can save one event object.
If you ask why I don't just use one single thread, they are in different processes.
Upvotes: 4
Views: 3620
Reputation: 24847
In general, no. By that time, another thread may have signaled it and, if there is no thread waiting, it will remain set. In the case of just two threads, then maybe you will be OK.
Why are you even bohering with such an 'optimization'. Using two events will be easier to debug.
Multiple threads, inter-thread and inter-process comms is difficult enough as it is. You should not add more complication.
Upvotes: 0
Reputation: 45173
The event becomes unsignaled when the waiter is released. There is no guarantee that the waiter will be released before the call to SetEvent
returns.
Upvotes: 4