std::shared...ex::try_lock(3)
π 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 π
trueif the lock was acquired successfully, otherwisefalse.
π 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms