std::shared...lock_shared(3)

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

std::shared_timed_mutex::lock_shared πŸ’…πŸ¦‹

okay so bestie, welcome to the C++ Standard Libary manual page for std::shared_timed_mutex::lock_shared. We're gonna get you comfy with this shared-locking situation, and yes, the manual name is folded right in here near the top. No cap. ✨

✨ NAME ✨

std::shared_timed_mutex::lock_shared - std::shared_timed_mutex::lock_shared. That's it, that's the name, twice, because the page said so. It's giving "shared lock member function" main character energy. πŸ‘‘

✨ Synopsis ✨

void lock_shared();  (since C++14)

So the lore: lock_shared() acquires shared ownership of the mutex. If another thread is holding the mutex in exclusive ownership, a call to lock_shared will block execution until shared ownership can be acquired. Like, it waits its turn, periodt. πŸ’…

If lock_shared is called by a thread that already owns the mutex in any mode (exclusive or shared), the behavior is undefined. Not "oops maybe fine" β€” undefined, bestie, so don't do it. 😭

If more than the implementation-defined maximum number of shared owners already locked the mutex in shared mode, lock_shared blocks execution until the number of shared owners is reduced. The maximum number of owners is guaranteed to be at least 10000. That's a big group chat, but there is a cap. πŸ‘‘

Prior unlock() operation on the same mutex synchronizes-with (as defined in std::memory_order) this operation. That's the memory-ordering lore, iykyk. 🌈

✨ Parameters ✨

(none) β€” literally zero parameters. Not one. Nada. πŸŽ€

✨ Return value ✨

(none) β€” it's void, so nothing comes back. It's giving silent but powerful. πŸ’€

✨ Exceptions ✨

Throws std::system_error when errors occur, including errors from the underlying operating system that would prevent lock from meeting its specifications. The mutex is not locked in the case of any exception being thrown. So if it throws, it's not secretly holding the lock. πŸ›Ÿ

✨ Notes ✨

lock_shared() is usually not called directly: std::shared_lock is used to manage shared locking. So you'll probably meet std::shared_lock first, and it's the main character managing the shared locking vibes. πŸ‘‘

✨ Example ✨

This section is incomplete Reason: no example

bestie, there is literally no example here. The page says so. πŸ™ˆ

✨ See also ✨

  • lock β€” locks the mutex, blocks if the mutex is not available (public member function)
  • try_lock_shared β€” tries to lock the mutex for shared ownership, returns if the mutex is not available (public member function)
  • unlock_shared β€” unlocks the mutex (shared ownership) (public member function)

✨ Category ✨

  • * Todo no example

kisses and shared locks, bestie πŸ’– β€” source: http://cppreference.com, date: 2024.06.10, page footer: std::shared...lock_shared(3). slay. ✨

πŸ“¦ where this page comes from