STD::UNIQUE_LOCK(3)

✨ NAME ✨

std::unique_lock< _Mutex > β€” A movable scoped lock type. πŸ’…

hiii bestie, welcome to the std::unique_lock< _Mutex >(3) page from the Library Functions Manual. The header up top is literally std::uniqu...< _Mutex >(3) (truncated, iykyk) and the manual name is Library Functions Manual. This page is about a movable scoped lock type, and we are keeping every single crumb. 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <mutex>

πŸ’– Public Types πŸ’–

  • typedef _Mutex mutex_type β€” the one and only public type, exactly as written. periodt. πŸŽ€

πŸ‘‘ Public Member Functions πŸ‘‘

okay so here is every single member function, in the exact order the original gives them. No skips, no merges, no invented lore. fr fr ✨

  • unique_lock (const unique_lock &)=delete β€” copy construction is deleted, so do not try it, bestie πŸ’…
  • unique_lock (mutex_type &__m) β€” constructor that takes mutex_type &__m.
  • unique_lock (mutex_type &__m, adopt_lock_t) noexcept β€” constructor with adopt_lock_t, and it is noexcept.
  • template<typename _Rep, typename _Period> unique_lock (mutex_type &__m, const chrono::duration< _Rep, _Period > &__rtime) β€” constructor with chrono::duration< _Rep, _Period > &__rtime.
  • template<typename _Clock, typename _Duration> unique_lock (mutex_type &__m, const chrono::time_point< _Clock, _Duration > &__atime) β€” constructor with chrono::time_point< _Clock, _Duration > &__atime.
  • unique_lock (mutex_type &__m, defer_lock_t) noexcept β€” constructor with defer_lock_t, and it is noexcept.
  • unique_lock (mutex_type &__m, try_to_lock_t) β€” constructor with try_to_lock_t.
  • unique_lock (unique_lock &&__u) noexcept β€” move constructor, and it is noexcept.
  • void lock () β€” member function named lock.
  • mutex_type * mutex () const noexcept β€” returns a mutex_type *, and it is const noexcept.
  • operator bool () const noexcept β€” bool conversion operator, and it is const noexcept.
  • unique_lock & operator= (const unique_lock &)=delete β€” copy assignment is deleted.
  • unique_lock & operator= (unique_lock &&__u) noexcept β€” move assignment, and it is noexcept.
  • bool owns_lock () const noexcept β€” returns bool, and it is const noexcept.
  • mutex_type * release () noexcept β€” returns mutex_type *, and it is noexcept.
  • void swap (unique_lock &__u) noexcept β€” member swap taking unique_lock &__u, and it is noexcept.
  • bool try_lock () β€” returns bool.
  • template<typename _Rep, typename _Period> bool try_lock_for (const chrono::duration< _Rep, _Period > &__rtime) β€” template returning bool, taking chrono::duration< _Rep, _Period > &__rtime.
  • template<typename _Clock, typename _Duration> bool try_lock_until (const chrono::time_point< _Clock, _Duration > &__atime) β€” template returning bool, taking chrono::time_point< _Clock, _Duration > &__atime.
  • void unlock () β€” member function named unlock.
  • (Note that these are not member symbols.) the original literally says this, bestie, so it stays.
  • template<typename _Mutex> void swap (unique_lock< _Mutex > &__x, unique_lock< _Mutex > &__y) noexcept β€” Swap overload for unique_lock objects. that description is exactly from the page.

πŸ’… Detailed Description πŸ’…

template<typename _Mutex>
class std::unique_lock< _Mutex >"A movable scoped lock type.

yes, there is a stray quote mark right there in the original, and I am not fixing it. we keep the details exactly. πŸ’€

okay so unique_lock controls mutex ownership within a scope. Ownership of the mutex can be delayed until after construction, and it can be transferred to another unique_lock by move construction or move assignment. If a mutex lock is owned when the destructor runs, ownership will be released. that is the whole vibe, no cap.

Since:

C++11


template<typename _Mutex> void swap (unique_lock< _Mutex > & __x, unique_lock< _Mutex > & __y) [related]

Swap overload for unique_lock objects.

ngl, this one has spaces in & __x and & __y, and it ends with [related]. The earlier Related Symbols version has &__x and &__y and noexcept. Both are real, both stay. slay. ✨


🌸 Author 🌸

Generated automatically by Doxygen for libstdc++ from the source code.


okay bye bestie πŸ’– the footer at the bottom says libstdc++ and std::uniqu...< _Mutex >(3), so that is the source/version and page-name sign-off. There is no date in that footer, fr fr, so I am not inventing one. Stay iconic, stay locked, mwah πŸ’…βœ¨

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms