This class is a simple wrapper around C++ standard library type std::mutex
. Thus, it is used to implement mutual exclusive access to resources by protecting critical code sections from being executed in parallel in concurrent threads.
When a pair of Acquire and Release invocations is performed within the same code block, then it is recommended to use a stack instantiation of class Owner to acquire and release objects of this class. Such a use is highly simplified with macros ALIB_LOCK and ALIB_LOCK_WITH.
This class does not allow nested calls to the method Acquire - method Release has to be invoked (from within the same thread that acquired this mutex), before any other thread can again gain access. Nested acquisitions constitute undefined behavior.
- Debug-Features
- Public member Dbg is available with debug-compilations. It offers the following features:
- An assertion is raised when nested use is performed.
- The object stores the actual owning thread and the source code position of the last acquirement.
- Releasing non-acquired instances, as well as destructing acquired one, raise an assertion.
- Field WaitTimeLimit enables the raise of ALib warnings in case a certain wait time is exceeded. Note that instead of wrapping
std::mutex
, with debug-compilations class std::timed_mutex
is wrapped.
- See also
-
Definition at line 58 of file lock.hpp.