std::timed_mutex::try_lock(3)

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

🌸 NAME 🌸

std::timed_mutex::try_lock β€” std::timed_mutex::try_lock.

hey bestie πŸ’– this is the std::timed_mutex::try_lock(3) page from the C++ Standard Libary manual (yes, that’s the manual name, typo and all β€” iykyk). It’s all about std::timed_mutex::try_lock and whether it can grab the lock right now. ✨

πŸ¦‹ Synopsis πŸ¦‹

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

try_lock() tries to lock the mutex. It returns immediately β€” no blocking, no waiting, just a quick vibe check. On successful lock acquisition it returns true; otherwise it returns false.

This function is allowed to fail spuriously and return false even if the mutex is not currently locked by any other thread. Yes, bestie, it can literally hand you a false for no obvious reason β€” that’s allowed. 🫠

If try_lock is called by a thread that already owns the mutex, the behavior is undefined. Do not do this, fr fr. Undefined behavior is not the move. 😭

A 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. Zero. Nada. 🫢 (none)

πŸ’– Return value πŸ’–

true if the lock was acquired successfully, otherwise false.

😭 Exceptions 😭

Throws nothing. Literally nothing. πŸ’…

πŸ¦‹ 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 πŸ’‹ this page came from http://cppreference.com, dated 2024.06.10, and the footer title is std::timed_mutex::try_lock(3) β€” periodt.

πŸ“¦ where this page comes from