[#absl-Mutex]
= xref:absl.adoc[absl]::Mutex
:relfileprefix: ../
:mrdocs:

A non&hyphen;reentrant mutually exclusive lock that also supports reader&hyphen;writer locking and conditional critical regions&period;

== Synopsis

Declared in `&lt;absl&sol;synchronization&sol;mutex&period;h&gt;`

[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&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/Mutex/2constructor-023.adoc[`Mutex`]         [.small]#[constructor]#
| Constructors
| xref:absl/Mutex/2destructor.adoc[`&#126;Mutex`] [.small]#[destructor]#
| Destroys this `Mutex`&period;
| xref:absl/Mutex/AssertHeld.adoc[`AssertHeld`] 
| Requires that the mutex be held exclusively (write mode) by this thread&period;
| xref:absl/Mutex/AssertNotHeld.adoc[`AssertNotHeld`] 
| Asserts that this thread does not hold this `Mutex` in any mode&period;
| xref:absl/Mutex/AssertReaderHeld.adoc[`AssertReaderHeld`] 
| Requires that the mutex be held at least in shared mode (read mode) by this thread&period;
| 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&period;
| 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&period;
| 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&period;
| xref:absl/Mutex/EnableDebugLog.adoc[`EnableDebugLog`] 
| Causes all subsequent uses of this `Mutex` to be logged&period;
| xref:absl/Mutex/EnableInvariantDebugging.adoc[`EnableInvariantDebugging`] 
| Registers an invariant predicate to be checked for this `Mutex` when invariant debugging has been enabled globally&period;
| xref:absl/Mutex/ForgetDeadlockInfo.adoc[`ForgetDeadlockInfo`] 
| Forgets any deadlock&hyphen;detection information previously gathered about this `Mutex`&period;
| xref:absl/Mutex/Lock-028.adoc[`Lock`]  [.small]#[deprecated]#
| Deprecated alias for `lock()`&period;
| xref:absl/Mutex/LockWhen.adoc[`LockWhen`] 
| Blocks until `cond` is `true` and the `Mutex` can be acquired, then atomically acquires it exclusively&period;
| xref:absl/Mutex/LockWhenWithDeadline.adoc[`LockWhenWithDeadline`] 
| Blocks until `cond` is `true` or the deadline passes, then atomically acquires this `Mutex` exclusively&period;
| xref:absl/Mutex/LockWhenWithTimeout.adoc[`LockWhenWithTimeout`] 
| Blocks until `cond` is `true` or the timeout expires, then atomically acquires this `Mutex` exclusively&period;
| xref:absl/Mutex/ReaderLock.adoc[`ReaderLock`]  [.small]#[deprecated]#
| Deprecated alias for `lock&lowbar;shared()`&period;
| xref:absl/Mutex/ReaderLockWhen.adoc[`ReaderLockWhen`] 
| Blocks until `cond` is `true` and the `Mutex` can be acquired, then atomically acquires it in shared mode&period;
| xref:absl/Mutex/ReaderLockWhenWithDeadline.adoc[`ReaderLockWhenWithDeadline`] 
| Blocks until `cond` is `true` or the deadline passes, then atomically acquires this `Mutex` in shared mode&period;
| xref:absl/Mutex/ReaderLockWhenWithTimeout.adoc[`ReaderLockWhenWithTimeout`] 
| Blocks until `cond` is `true` or the timeout expires, then atomically acquires this `Mutex` in shared mode&period;
| xref:absl/Mutex/ReaderTryLock.adoc[`ReaderTryLock`]  [.small]#[deprecated]#
| Deprecated alias for `try&lowbar;lock&lowbar;shared()`&period;
| xref:absl/Mutex/ReaderUnlock.adoc[`ReaderUnlock`]  [.small]#[deprecated]#
| Deprecated alias for `unlock&lowbar;shared()`&period;
| xref:absl/Mutex/TryLock.adoc[`TryLock`]  [.small]#[deprecated]#
| Deprecated alias for `try&lowbar;lock()`&period;
| xref:absl/Mutex/Unlock-0f.adoc[`Unlock`]  [.small]#[deprecated]#
| Deprecated alias for `unlock()`&period;
| xref:absl/Mutex/WriterLock.adoc[`WriterLock`]  [.small]#[deprecated]#
| Deprecated writer alias for `lock()`&period;
| 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&period;
| xref:absl/Mutex/WriterLockWhenWithDeadline.adoc[`WriterLockWhenWithDeadline`] 
| Blocks until `cond` is `true` or the deadline passes, then atomically acquires this `Mutex` in write (exclusive) mode&period;
| xref:absl/Mutex/WriterLockWhenWithTimeout.adoc[`WriterLockWhenWithTimeout`] 
| Blocks until `cond` is `true` or the timeout expires, then atomically acquires this `Mutex` in write (exclusive) mode&period;
| xref:absl/Mutex/WriterTryLock.adoc[`WriterTryLock`]  [.small]#[deprecated]#
| Deprecated writer alias for `try&lowbar;lock()`&period;
| xref:absl/Mutex/WriterUnlock.adoc[`WriterUnlock`]  [.small]#[deprecated]#
| Deprecated writer alias for `unlock()`&period;
| xref:absl/Mutex/lock-025.adoc[`lock`] 
| Blocks the calling thread, if necessary, until this `Mutex` is free, and then acquires it exclusively&period;
| xref:absl/Mutex/lock_shared.adoc[`lock&lowbar;shared`] 
| Blocks the calling thread, if necessary, until this `Mutex` is either free or in shared mode, and then acquires a share of it&period;
| xref:absl/Mutex/try_lock.adoc[`try&lowbar;lock`] 
| Tries to acquire this `Mutex` exclusively without blocking&period;
| xref:absl/Mutex/try_lock_shared.adoc[`try&lowbar;lock&lowbar;shared`] 
| Tries to acquire this `Mutex` for shared access without blocking&period;
| xref:absl/Mutex/unlock-0c.adoc[`unlock`] 
| Releases this `Mutex` and returns it from the exclusive&sol;write state to the free state&period;
| xref:absl/Mutex/unlock_shared.adoc[`unlock&lowbar;shared`] 
| Releases a read share of this `Mutex`&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/Mutex/InternalAttemptToUseMutexInFatalSignalHandler.adoc[`InternalAttemptToUseMutexInFatalSignalHandler`] 
| Prepares the `Mutex` implementation for re&hyphen;entry from within a fatal signal handler&period;
|===


== 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`&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
