std::shared...lock_shared(3)

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

πŸ’– NAME πŸ’–

std::shared_mutex::try_lock_shared β€” ok so it's literally std::shared_mutex::try_lock_shared, the shared-mode try-lock bestie of the C++ Standard Library manual (std::shared...lock_shared(3), iykyk) 🫢


✨ Synopsis ✨

bool try_lock_shared();  // (since C++17)

So here's the vibe: this function tries to lock the mutex in shared mode, and it returns immediately β€” no waiting, no blocking, no "hold on let me think about it" energy πŸ’… On a successful lock acquisition it returns true, otherwise it returns false. Periodt.

Heads up bestie: this function is allowed to fail spuriously and return false even if the mutex is not currently exclusively locked by any other thread 😭 Not me getting rejected for no reason fr fr.

A prior unlock() operation on the same mutex synchronizes-with (as defined in std::memory_order) this operation if it returns true ⭐

🚨 Ok this one matters: the behavior is undefined if the calling thread already owns the mutex in any mode. Any mode. Don't do it. πŸ™ˆ

πŸŽ€ Parameters πŸŽ€

(none) β€” yeah, she takes nothing, she's low maintenance ✨


🌸 Return value 🌸

true if the lock was acquired successfully, otherwise false. That's it, that's the whole story πŸ’–


πŸ¦‹ Exceptions πŸ¦‹

Throws nothing. Not a single thing. Iconic behavior honestly πŸ‘‘


πŸ“ Example πŸ“

This section is incomplete.

Reason: no example πŸ™ˆ


🌈 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

🧚 She's giving "I tried my best and I'm leaving immediately" energy and honestly? Respect.

Ok that's the whole page bestie, go forth and lock responsibly πŸ’…βœ¨

Source/version + date check: this one's straight from http://cppreference.com, dated 2024.06.10 β€” the std::shared...lock_shared(3) page, no cap πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from