This class is a simple wrapper around C++ standard library type std::recursive_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 AcquireRecursive and ReleaseRecursive invocations is performed within the same code block, then it is recommended to use a stack instantiation of class OwnerRecursive to acquire and release objects of this class. Such a use is greatly simplified with macros ALIB_LOCK_RECURSIVE and ALIB_LOCK_RECURSIVE_WITH.
Nested acquisitions are supported with this type. An instance of this class is released when an equal number of invocations to AcquireRecursive and ReleaseRecursive have been performed.
This class has slightly reduced performance in comparison to non-recursive type Lock. Not only for this reason, non-nested locking is the preferred technique. But there are situations where nested locks are just unavoidable.
- Debug-Features
- Public member Dbg is available with debug-compilations. It offers the following features:
- 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.
- A warning threshold for the number of nested acquisitions can be defined with public member int RecursionLimit.
- Field WaitTimeLimit enables the raise of ALib warnings in case a certain wait time is exceeded. Note that instead of wrapping
std::recursive_mutex, with debug-compilations class std::recursive_timed_mutex is wrapped.
- Availability
- This type is not available if the configuration macro ALIB_SINGLE_THREADED is set.
- See also
-
Definition at line 48 of file recursivelock.inl.