std::shared...ex::try_lock(3)

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

πŸ’– NAME πŸ’–

Okay bestie, welcome to the std::shared...ex::try_lock(3) page from the C++ Standard Libary manual. The actual NAME is std::shared_mutex::try_lock - std::shared_mutex::try_lock β€” yes, it’s giving function-and-itself, iconic.

✨ Synopsis ✨

bool try_lock();  (since C++17)

Tries to lock the mutex. Returns immediately. On successful lock acquisition returns true, otherwise returns false.

This function is allowed to fail spuriously and return false even if the mutex is not currently locked by any other thread. So like… it can just say no for no reason, no cap.

If try_lock is called by a thread that already owns the mutex in any mode (shared or exclusive), the behavior is undefined. That’s UB, bestie β€” do not.

Prior unlock() operation on the same mutex synchronizes-with (as defined in std::memory_order) this operation if it returns true. Note that prior lock() does not synchronize with this operation if it returns false.

πŸŽ€ Parameters πŸŽ€

  • (none) β€” literally none. No arguments, no stress. periodt.

🌟 Return value 🌟

  • true if the lock was acquired successfully, otherwise false.

πŸ’€ Exceptions πŸ’€

  • Throws nothing. β€” literally nothing, she’s not throwing hands. slay.

🧚 Example 🧚

  • This section is incomplete
  • Reason: no example
Not me reading β€œno example” and feeling personally attacked 😭 but okay, the docs said what they said.

πŸ‘€ See also πŸ‘€

  • lock β€” locks the mutex, blocks if the mutex is not available (public member function)
  • unlock β€” unlocks the mutex (public member function)
  • C documentation for mtx_trylock

πŸ“ Category πŸ“

  • Todo no example

Sign-off from the footer, for the record: source/version http://cppreference.com, date 2024.06.10, and the page title is std::shared...ex::try_lock(3). Slay, go forth and lock responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from