std::recurs...x::try_lock(3)

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

✨ NAME ✨

okay so welcome to the std::recurs...x::try_lock(3) page from the C++ Standard Libary (yes, that’s the manual name up top, and yes, the title is truncated β€” we don’t ask questions πŸ’…). The function is std::recursive_timed_mutex::try_lock, and the NAME section literally gives us std::recursive_timed_mutex::try_lock - / std::recursive_timed_mutex::try_lock, so it’s giving β€œthe name is the name” energy, no cap.


πŸ¦‹ Synopsis πŸ¦‹

bool try_lock() noexcept;  (since C++11)

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. Lowkey wild, but that’s the rule 😭.

A thread may call try_lock on a recursive mutex repeatedly. Successful calls to try_lock increment the ownership count: the mutex will only be released after the thread makes a matching number of calls to unlock.

The maximum number of levels of ownership is unspecified. A call to try_lock will return false if this number is exceeded.

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, bestie. No args, no stress.


πŸ’– Return value πŸ’–

true if the lock was acquired successfully, otherwise false.


🌸 Exceptions 🌸

Throws nothing. Not a single exception. Periodt.


🧚 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_for β€” tries to lock the mutex, returns if the mutex has been unavailable for the specified timeout duration (public member function)
  • try_lock_until β€” tries to lock the mutex, returns if the mutex has been unavailable until specified time point has been reached (public member function)
  • unlock β€” unlocks the mutex (public member function)
  • C documentation for mtx_trylock

🌈 Category 🌈

  • Todo no example

mwah πŸ’‹ source: http://cppreference.com Β· version/date: 2024.06.10 Β· page title: std::recurs...x::try_lock(3) β€” catch u later, bestie! 🫢

πŸ“¦ where this page comes from