Signaling with Wait and Pulse

In one of our previous examples, we've used the Lock class whose implementation uses Monitor::Enter and Monitor::Exit. Another feature of the Monitor object is very important: the Monitor::Wait and Monitor::Pulse methods (and the Pulse variation PulseAll). These methods also make EAP constructs. Their ability to wait until a signal is received from another thread makes them excellent for usage. One of the most important features is that they prevent spinning, because of which no processor time is wasted. The only constraint is that they must be enclosed with locks (Monitor::Enter and Monitor::Exit). Once again, we're introducing the Lock class in order to gain exclusive access to shared objects.

Our following example ...

Get C++ Multithreading Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.