std::mutex(3)
πΈ NAME πΈ
std::mutex β it's giving "the standard mutex type" and honestly? she's the blueprint π
This one lives in the libstdc++ manual, section 3, so if you ever need to find her again: std::mutex(3), library functions manual, periodt.
β¨ SYNOPSIS β¨
#include <mutex>
π Public Types
typedef __native_type * native_handle_typeβ bestie this is the raw handle type, the under-the-hood little guy that the platform actually gives you π«Ά
π Public Member Functions
mutex (const mutex &) = deleteβ copying? not allowed. not on the table. the compiler said no and she meant it πvoid lock ()β grab the lock. (but pls read the description below before you go calling this directly, i'm begging π)native_handle_type native_handle () noexceptβ hands you the native handle. markednoexcept, so she will not be throwing tantrums β¨mutex & operator= (const mutex &) = deleteβ assignment? also deleted. she does not want to be anyone else's copy, main character only πbool try_lock () noexceptβ tries to lock, tells you if it worked, and it'snoexcept. no drama, just vibes πvoid unlock ()β release the lock. (again: don't do this by hand, keep reading π)
π¦ Detailed Description π¦
The standard mutex type. That's her. That's the whole girl.
She's a simple, non-recursive, non-timed mutex. Let's unpack that real quick:
- simple β does one job, does it well, no extra features, no notes π
- non-recursive β if the same thread tries to lock her twice, that's not a "self-love moment", that's a problem. she is NOT reentrant, do not test her π«
- non-timed β there's no
try_lock_for/try_lock_untilenergy here. if you need a clock involved, this is not the mutex for you β°
π¨ OKAY THIS IS THE IMPORTANT PART π¨ Do not calllock()andunlock()directly, bestie. Use a scoped lock type instead, likestd::unique_lock,std::lock_guard, or β since C++17 βstd::scoped_lock. Those handle the unlocking for you so you can't forget and deadlock your entire program. rawlock()/unlock()is how you end up crying at 3am. use the scoped ones. i'm not asking, i'm telling π
β Since β
C++11 β she's been iconic since day one, no cap π
πΈ Author πΈ
Generated automatically by Doxygen for libstdc++ from the source code. so technically nobody wrote her, she was born from the source, which is honestly very main character of her π¦
okay that's the whole page, and the sign-off: this came from the libstdc++ manual β std::mutex(3), library functions manual, libstdc++, section 3, mwah π stay locked and loaded (safely, with a scoped lock) bestie π«Άβ¨
π¦ 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