STD::LOCK_GUARD(3)

πŸ’– std::lock_guard< _Mutex > πŸ’–

okay bestie, gather round, because we're talking about std::lock_guard< _Mutex > from the std namespace, and it lives in the Library Functions Manual. it's a simple scoped lock type. that's the whole vibe. simple. scoped. lock. periodt. πŸŽ€


✨ NAME ✨

std::lock_guard< _Mutex > β€” a simple scoped lock type. no cap, that's literally the tagline.


🌸 SYNOPSIS 🌸

#include <mutex>

πŸ¦‹ Public Types πŸ¦‹

  • typedef _Mutex mutex_type β€” yeah so this is just _Mutex wearing a little name tag. that's the mutex type you're working with, bestie.

πŸŽ€ Public Member Functions πŸŽ€

  • lock_guard (const lock_guard &)=delete β€” copy constructor? deleted. you cannot copy this. not today, not ever. πŸ’€
  • lock_guard (mutex_type &__m) β€” the main character constructor. hand it a mutex reference and it locks it.
  • lock_guard (mutex_type &__m, adopt_lock_t) noexcept β€” the "I already locked it myself, don't touch anything" constructor, marked noexcept.
  • lock_guard & operator= (const lock_guard &)=delete β€” copy assignment? also deleted. assignment is NOT giving. 🚫

πŸ‘‘ Detailed Description πŸ‘‘

template<typename _Mutex>
    class std::lock_guard< _Mutex >

a simple scoped lock type. πŸ’…

so here's the tea: a lock_guard controls mutex ownership within a scope, and it releases that ownership in the destructor. that's it. that's the whole job. you make one, it owns the mutex for as long as it's alive, and the second it dies (scope ends, bye bye), the mutex gets released. RAII queen behavior honestly. πŸ”₯

Since

C++11 β€” she's been iconic since 2011 and she's not slowing down. ⭐


🫢 Author 🫢

Generated automatically by Doxygen for libstdc++ from the source code. so like, a robot wrote this, but a very thorough robot. respect. πŸ€–βœ¨


heads up bestie: both the copy constructor and the copy assignment operator are =deleted, so if you try to copy a lock_guard the compiler will simply refuse. that's not a bug, that's the design, and it's protecting you fr fr. πŸ™ˆ

and that's the whole page, babe β€” this was std::lock_...d< _Mutex >(3) from the libstdc++ girlies, delivered to you straight from the Library Functions Manual. thanks for coming to my ted talk, go forth and guard your scopes responsibly. 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