AlgoMaster Logo

std::unique_lock

Last Updated: June 6, 2026

Medium Priority
30 min read

std::unique_lock (since C++11, in <mutex>) is the flexible RAII wrapper for mutexes. It does everything std::lock_guard does, plus a list of extras that the simpler wrapper omits: early unlock and re-lock, deferred locking, try-locking, timed locking, transfer of ownership across scopes, and integration with condition variables. The cost is a slightly larger object and a small per-operation overhead. This chapter covers when to use unique_lock over lock_guard, the tag constructors that change its behavior, the timed variants, the condition-variable connection, and a comparison table at the end.

Premium Content

Subscribe to unlock full access to this content and more premium articles.