Unique_lock
std::unique_lock is a C++ standard library class template that manages exclusive ownership of a mutex and supports deferred locking, unlocking, and ownership transfer.
Object-Oriented Software Design in C++
A C++ standard library lock-management class that provides exclusive ownership of a mutex and releases that ownership automatically when the lock object is destroyed.
- How it is used
- Coordinates exclusive access to shared resources and supplies the lock object required by condition-variable waits.
- How deep it goes
- Explains construction, scope-based unlocking, reader-writer behavior, and condition-variable waiting, without detailing the class implementation.
- Examples
- Uses technician and logger threads sharing a meter, plus producer and consumer threads sharing a bounded queue.
- What you can do after
- Apply it via C++ mutexes and condition variables to guard critical regions and synchronize access to shared data.
Read how Object-Oriented Software Design in C++ explains unique_lock →
C++ Concurrency in Action, Second Edition
`std::unique_lock` is a C++ standard library class template that manages ownership of a mutex lock and supports deferred locking, unlocking, and ownership transfer.
- How it is used
- Manages mutex ownership when locking must be deferred, released, or transferred between scopes.
- How deep it goes
- Explains deferred acquisition, ownership tracking, destructor behavior, move transfer, and costs without enumerating the full API.
- Examples
- Uses a two-mutex swap, a lock-returning data-preparation function, and exclusive updates with shared_mutex.
- What you can do after
- Apply deferred locking to acquire multiple mutexes safely or transfer a held lock to a caller.
Read how C++ Concurrency in Action, Second Edition explains unique_lock →
Related concepts
- ownership transferuses · Ownership transfer is the reassignment of responsibility for managing a value or resource from one entity to another.
- std::moveuses · std::move is a C++ standard-library function template that casts an expression to an rvalue reference, enabling move operations.
- lock_guardcontrasts with · std::lock_guard is a C++ standard library class template that acquires a mutex when constructed and releases it when destroyed.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

