Class monitor_base

poet::monitor_base — A base class for monitor objects.


class monitor_base {

  // protected member functions
  void wait() const;
  template<typename Pred> void wait(Pred) const;
  void notify_all() const;
  void notify_one() const;


Deriving from monitor_base allows a class (whose objects are managed by a monitor_ptr or contained in a monitor) to wait on conditions inside member functions, releasing the monitor's mutex until the condition is satisfied. See "Monitor Object: An Object Behavioral Pattern for Concurrent Programming" by Douglas C. Schmidt for more information on monitor objects.

Support for a timed_wait() could be added in the future.

Example Code

monitor_base protected member functions

  1. void wait() const;
    template<typename Pred> void wait(Pred pred) const;

    Blocks until the object is woken up by another thread via monitor_base::notify_all() or monitor_base::notify_one(). The mutex in the object's associated monitor_ptr is unlocked before the thread goes to sleep, and then automatically reaquired when the thread wakes up again.

    If the pred parameter is supplied, the call will return when pred() returns true. pred() will be checked when wait() is first entered, and whenever the thread is woken by a notification. The mutex will be locked when pred() is called.

  2. void notify_all() const;

    Wakes all threads which are currently blocking in monitor_base::wait() calls on this object. If no threads are waiting, it has no effect.

  3. void notify_one() const;

    Wakes a single thread which is currently blocking in a monitor_base::wait() call on this object. If no threads are waiting, it has no effect.