std::shared...lock_shared(3)

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

πŸ’… std::shared...lock_shared(3) β€” C++ Standard Libary bestie page πŸ’…

okay bestie, welcome to the manual page for std::shared...lock_shared(3) from the C++ Standard Libary (that’s the manual name, don’t come for me 😭). Hydrate, stretch, and let’s get into this shared-lock situation. 🫢✨

🌸 NAME 🌸

std::shared_timed_mutex::try_lock_shared - std::shared_timed_mutex::try_lock_shared

πŸ“š Synopsis πŸ“š

bool try_lock_shared();  (since C++14)

okay so this function tries to lock the mutex in shared mode. It returns immediately β€” no blocking, no waiting, no β€œgimme a sec.” If the lock acquisition is successful it returns true; otherwise it returns false. πŸ’…

Heads up though: this function is allowed to fail spuriously and return false even if the mutex is not currently exclusively locked by any other thread. So a false doesn’t always mean someone else is holding it exclusively β€” rude, but legal. 😭

If a prior unlock() operation on the same mutex happens, it synchronizes-with (as defined in std::memory_order) this operation when this one returns true. That’s the memory-order tea. 🍡

⚠️ UNDEFINED BEHAVIOR ALERT: the behavior is undefined if the calling thread already owns the mutex in any mode. Do not do that. Not even a little. πŸ’€

πŸŽ€ Parameters πŸŽ€

Literally none. Zero. Nada. This function takes no parameters. 🧚

⭐ Return value ⭐

true if the lock was acquired successfully, otherwise false. That’s it. That’s the whole vibe check. βœ…

πŸ¦‹ Exceptions πŸ¦‹

It throws absolutely nothing. Not a single exception. Silent. Iconic. ✨

πŸ“ Example πŸ“

This section is incomplete Reason: no example

Yeah bestie, they really left us hanging β€” no example here. πŸ™ˆ

πŸ”₯ See also πŸ”₯

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

🏷️ Category 🏷️

  • * Todo no example

made with πŸ’– by http://cppreference.com β€” version/date: 2024.06.10 🌈🫢

πŸ“¦ where this page comes from