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. marked noexcept, 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's noexcept. 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_until energy here. if you need a clock involved, this is not the mutex for you ⏰
🚨 OKAY THIS IS THE IMPORTANT PART 🚨 Do not call lock() and unlock() directly, bestie. Use a scoped lock type instead, like std::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. raw lock()/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