I read about event, which allow me to wait for other thread: AutoResetEvent
and ManualResetEvent
.
What are the differences between these two classes? Which class is better for a highly concurrent program?
I read about event, which allow me to wait for other thread: AutoResetEvent
and ManualResetEvent
.
What are the differences between these two classes? Which class is better for a highly concurrent program?
The difference is in what happens when the event is signaled (set).
In general I find it easier to work with manual reset events because in most cases it is a bit more straight-forward to determine the state of the event at any given time.
That said there are cases when the behavior of the auto-reset event lends itself better to achieving synchronization because you are guaranteed that only one of the waiting threads will be signaled. So if you have a producer/multiple-consumers scenario where any, but only, one consumer should be signaled you should consider the auto-reset event.