O'Reilly logo

C++ Multithreading Cookbook by Milos Ljumovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required