Monitor Object -- Rainer Grimm
The Monitor Object design pattern synchronizes concurrent member function execution to ensure that only one member function runs within an object at a time. It also allows an object's member functions to schedule their execution sequences cooperatively.
Monitor Object
by Rainer Grimm
From the article:
Problem
If many threads access a shared object concurrently, the following challenges exist.
- Due to the concurrent access, the shared object must be protected from non-synchronized read and write operations to avoid data races.
- The necessary synchronization should be part of the implementation, not the interface.
- When a thread is done with the shared object, a notification should be triggered so the next thread can use the shared object. This mechanism helps avoid and improves the system's overall performance.
- After the execution of a member function, the invariants of the shared object must hold.
Solution
A client (thread) can access the Monitor Object's synchronized member functions, and due to the monitor lock, only one synchronized member function can run at any given time. Each Monitor Object has a monitor condition that notifies the waiting clients.

Registration is now open for CppCon 2023! The conference starts on October 1 and will be held 
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
The latest major version of the
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
The active object design pattern decouples method execution from method invocation for objects that each reside in their own thread of control.The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests.
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
A few years ago, I showed an interesting implementation for self-registering classes in factories. It works, but one step might be at the edge of Undefined behavior. Fortunately, with C++20, its new constinit keyword, we can update the code and ensure it’s super safe.