Implementing AutoResetEvent

Implementing AutoResetEvent

You are asked to design a class similar to C#'s AutoResetEvent class. The AutoResetEvent synchronization primitive allows any number of threads to wait on the event object and allows a single thread to be released on being signaled. Additionally, the AutoResetEvent object can be initialized in the signaled state, in which case the first thread attempting to wait on the object doesn't block. However, the object goes back to unsignaled state after a thread has been released. If an AutoResetEvent object is signaled multiple times in the absence of any waiting threads, the object allows a single thread to proceed forward when multiple threads subsequently invoke wait() on it. In other words, multiple signals collapse into one when there are no waiting threads.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.