std::lock_g...::lock_guard(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::lock_g...::lock_guard(3) πŸ’–

okay so bestie, you're in the C++ Standard Libary manual, and this page is all about std::lock_guard::lock_guard. yes, the NAME is literally std::lock_guard::lock_guard β€” std::lock_guard::lock_guard. it's giving constructor main-character energy, fr fr. πŸ’…


✨ Synopsis ✨

three versions, all (since C++11), no cap:

explicit lock_guard( mutex_type& m );             (1) (since C++11)
lock_guard( mutex_type& m, std::adopt_lock_t t ); (2) (since C++11)
lock_guard( const lock_guard& ) = delete;         (3) (since C++11)

this whole situation acquires ownership of the given mutex m. 🫢

  1. Effectively calls m.lock().
  2. Acquires ownership of the mutex m without attempting to lock it. The behavior is undefined if the current thread does not hold a non-shared lock (i.e., a lock acquired by lock, try_lock, try_lock_for, or try_lock_until) on m. πŸ’€
  3. Copy constructor is deleted.
The behavior is undefined if m is destroyed before the lock_guard object is. like, do not let that happen, bestie β€” undefined behavior is not the vibe. 😭

πŸŽ€ Parameters πŸŽ€

  • m β€” mutex to acquire ownership of
  • t β€” tag parameter used to select non-locking version of the constructor

😭 Exceptions 😭

  1. Throws any exceptions thrown by m.lock().
  2. Throws nothing.

✨ okay that's the whole page, bestie. source/version: cppreference.com Β· date: 2024.06.10 Β· manual: C++ Standard Libary Β· URL: http://cppreference.com Β· std::lock_g...::lock_guard(3) πŸ¦‹

πŸ“¦ where this page comes from