[#absl-Mutex] = xref:absl.adoc[absl]::Mutex :relfileprefix: ../ :mrdocs: A non‐reentrant mutually exclusive lock that also supports reader‐writer locking and conditional critical regions. == Synopsis Declared in `<absl/synchronization/mutex.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class Mutex; ---- == Type Aliases [cols="1,4"] |=== | Name| Description | xref:absl/Mutex/MuHow.adoc[`MuHow`] | A constant that indicates how a lock should be acquired. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/Mutex/2constructor-023.adoc[`Mutex`] [.small]#[constructor]# | Constructors | xref:absl/Mutex/2destructor.adoc[`~Mutex`] [.small]#[destructor]# | Destroys this `Mutex`. | xref:absl/Mutex/AssertHeld.adoc[`AssertHeld`] | Requires that the mutex be held exclusively (write mode) by this thread. | xref:absl/Mutex/AssertNotHeld.adoc[`AssertNotHeld`] | Asserts that this thread does not hold this `Mutex` in any mode. | xref:absl/Mutex/AssertReaderHeld.adoc[`AssertReaderHeld`] | Requires that the mutex be held at least in shared mode (read mode) by this thread. | xref:absl/Mutex/Await.adoc[`Await`] | Unlocks this `Mutex` and blocks until `cond` is `true` and the `Mutex` can be reacquired, then reacquires it in the same mode. | xref:absl/Mutex/AwaitWithDeadline.adoc[`AwaitWithDeadline`] | Unlocks this `Mutex` and blocks until `cond` is `true` or the deadline passes, then reacquires it in the same mode. | xref:absl/Mutex/AwaitWithTimeout.adoc[`AwaitWithTimeout`] | Unlocks this `Mutex` and blocks until `cond` is `true` or the timeout expires, then reacquires it in the same mode. | xref:absl/Mutex/EnableDebugLog.adoc[`EnableDebugLog`] | Causes all subsequent uses of this `Mutex` to be logged. | xref:absl/Mutex/EnableInvariantDebugging.adoc[`EnableInvariantDebugging`] | Registers an invariant predicate to be checked for this `Mutex` when invariant debugging has been enabled globally. | xref:absl/Mutex/ForgetDeadlockInfo.adoc[`ForgetDeadlockInfo`] | Forgets any deadlock‐detection information previously gathered about this `Mutex`. | xref:absl/Mutex/Lock-028.adoc[`Lock`] [.small]#[deprecated]# | Deprecated alias for `lock()`. | xref:absl/Mutex/LockWhen.adoc[`LockWhen`] | Blocks until `cond` is `true` and the `Mutex` can be acquired, then atomically acquires it exclusively. | xref:absl/Mutex/LockWhenWithDeadline.adoc[`LockWhenWithDeadline`] | Blocks until `cond` is `true` or the deadline passes, then atomically acquires this `Mutex` exclusively. | xref:absl/Mutex/LockWhenWithTimeout.adoc[`LockWhenWithTimeout`] | Blocks until `cond` is `true` or the timeout expires, then atomically acquires this `Mutex` exclusively. | xref:absl/Mutex/ReaderLock.adoc[`ReaderLock`] [.small]#[deprecated]# | Deprecated alias for `lock_shared()`. | xref:absl/Mutex/ReaderLockWhen.adoc[`ReaderLockWhen`] | Blocks until `cond` is `true` and the `Mutex` can be acquired, then atomically acquires it in shared mode. | xref:absl/Mutex/ReaderLockWhenWithDeadline.adoc[`ReaderLockWhenWithDeadline`] | Blocks until `cond` is `true` or the deadline passes, then atomically acquires this `Mutex` in shared mode. | xref:absl/Mutex/ReaderLockWhenWithTimeout.adoc[`ReaderLockWhenWithTimeout`] | Blocks until `cond` is `true` or the timeout expires, then atomically acquires this `Mutex` in shared mode. | xref:absl/Mutex/ReaderTryLock.adoc[`ReaderTryLock`] [.small]#[deprecated]# | Deprecated alias for `try_lock_shared()`. | xref:absl/Mutex/ReaderUnlock.adoc[`ReaderUnlock`] [.small]#[deprecated]# | Deprecated alias for `unlock_shared()`. | xref:absl/Mutex/TryLock.adoc[`TryLock`] [.small]#[deprecated]# | Deprecated alias for `try_lock()`. | xref:absl/Mutex/Unlock-0f.adoc[`Unlock`] [.small]#[deprecated]# | Deprecated alias for `unlock()`. | xref:absl/Mutex/WriterLock.adoc[`WriterLock`] [.small]#[deprecated]# | Deprecated writer alias for `lock()`. | xref:absl/Mutex/WriterLockWhen.adoc[`WriterLockWhen`] | Blocks until `cond` is `true` and the `Mutex` can be acquired, then atomically acquires it in write (exclusive) mode. | xref:absl/Mutex/WriterLockWhenWithDeadline.adoc[`WriterLockWhenWithDeadline`] | Blocks until `cond` is `true` or the deadline passes, then atomically acquires this `Mutex` in write (exclusive) mode. | xref:absl/Mutex/WriterLockWhenWithTimeout.adoc[`WriterLockWhenWithTimeout`] | Blocks until `cond` is `true` or the timeout expires, then atomically acquires this `Mutex` in write (exclusive) mode. | xref:absl/Mutex/WriterTryLock.adoc[`WriterTryLock`] [.small]#[deprecated]# | Deprecated writer alias for `try_lock()`. | xref:absl/Mutex/WriterUnlock.adoc[`WriterUnlock`] [.small]#[deprecated]# | Deprecated writer alias for `unlock()`. | xref:absl/Mutex/lock-025.adoc[`lock`] | Blocks the calling thread, if necessary, until this `Mutex` is free, and then acquires it exclusively. | xref:absl/Mutex/lock_shared.adoc[`lock_shared`] | Blocks the calling thread, if necessary, until this `Mutex` is either free or in shared mode, and then acquires a share of it. | xref:absl/Mutex/try_lock.adoc[`try_lock`] | Tries to acquire this `Mutex` exclusively without blocking. | xref:absl/Mutex/try_lock_shared.adoc[`try_lock_shared`] | Tries to acquire this `Mutex` for shared access without blocking. | xref:absl/Mutex/unlock-0c.adoc[`unlock`] | Releases this `Mutex` and returns it from the exclusive/write state to the free state. | xref:absl/Mutex/unlock_shared.adoc[`unlock_shared`] | Releases a read share of this `Mutex`. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/Mutex/InternalAttemptToUseMutexInFatalSignalHandler.adoc[`InternalAttemptToUseMutexInFatalSignalHandler`] | Prepares the `Mutex` implementation for re‐entry from within a fatal signal handler. |=== == Friends [cols="1,4"] |=== | Name| Description | `xref:absl/CondVar.adoc[absl::CondVar]` | A condition variable that can be signaled to wake threads waiting on state evaluated outside a `Mutex`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#