Reputation: 1148
I do WaitForSingleObject(handle, timeout);
if handle is already signaled before the call to WaitForSingleObject
, what will the function return?
I thought it should immediately return a WAIT_OBJECT_0
...but in my case, it waits for the event to be set and since that does not happen (the event is already set), it times out.
Pls advise.
Upvotes: 3
Views: 9519
Reputation: 69632
Depends on event. What you expect is true for manual reset event, and auto-reset events don't keep the signaled state: Event Objects (Windows).
Auto-reset event An event object whose state remains signaled until a single waiting thread is released, at which time the system automatically sets the state to nonsignaled.
If no threads are waiting, the event object's state remains signaled. If more than one thread is waiting, a waiting thread is selected. Do not assume a first-in, first-out (FIFO) order. External events such as kernel-mode APCs can change the wait order.
Upvotes: 9