a question about event object
-
There is an autoreset event object ,and it's initial state is signaled. Suppose there are two threads in a process, called A and B, are wating for this event object infinitely. Either thread will change the event's state to nonsignaled if it's waiting function call succeeds, and the other thread will still wait on that object. Am I right? If thread A's waiting funcion call succeeds, then before it call ResetEvent, A terminated. How about B, Will B still wait for this event object? The event object's is signaled, or nonsignaled? Thank you all :)
-
There is an autoreset event object ,and it's initial state is signaled. Suppose there are two threads in a process, called A and B, are wating for this event object infinitely. Either thread will change the event's state to nonsignaled if it's waiting function call succeeds, and the other thread will still wait on that object. Am I right? If thread A's waiting funcion call succeeds, then before it call ResetEvent, A terminated. How about B, Will B still wait for this event object? The event object's is signaled, or nonsignaled? Thank you all :)
ResetEvent
is only used for manual events. You are talking about auto-reset events. Auto reset means that the event automatically returns to the non-signalled state after a thread which was waiting for the event to be signalled is released. If thread A, which was released, terminates before it callsSetEvent
to signal the event, thread B will be stuck waiting since there is nothing to change the state of the event to signalled. Judy -
ResetEvent
is only used for manual events. You are talking about auto-reset events. Auto reset means that the event automatically returns to the non-signalled state after a thread which was waiting for the event to be signalled is released. If thread A, which was released, terminates before it callsSetEvent
to signal the event, thread B will be stuck waiting since there is nothing to change the state of the event to signalled. JudyThank you JudyL_FL! I have try it, and found that thread B will be waiting for ever, hence it will have no chance to execute. So I think it would be dangerous to use autoreset event to synchronous threads. :)
-
Thank you JudyL_FL! I have try it, and found that thread B will be waiting for ever, hence it will have no chance to execute. So I think it would be dangerous to use autoreset event to synchronous threads. :)
zengkun100 wrote:
So I think it would be dangerous to use autoreset event to synchronous threads
It all depends on how the threads are synchronized. Each has its place. Refer to the MSDN for an example that uses both. Using Event Objects[^]. Manual reset events can also cause deadlocks if a thread terminates before it signals the event. Synchronization and the avoidance of deadlocks are one of the big issues when doing multi-threading. Judy
-
zengkun100 wrote:
So I think it would be dangerous to use autoreset event to synchronous threads
It all depends on how the threads are synchronized. Each has its place. Refer to the MSDN for an example that uses both. Using Event Objects[^]. Manual reset events can also cause deadlocks if a thread terminates before it signals the event. Synchronization and the avoidance of deadlocks are one of the big issues when doing multi-threading. Judy
Thank you Judy :) Each coin has two sides, I will think more about thread synchronization.