std::shared_lock::try_lock(3)

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

πŸ’… NAME πŸ’…

okay so bestie, welcome to the std::shared_lock::try_lock page from the C++ Standard Libary manual ✨ the name is std::shared_lock::try_lock β€” and yes, it is also literally std::shared_lock::try_lock. iconic redundancy, we love to see it πŸŽ€


🌸 Synopsis 🌸

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

Tries to lock the associated mutex in shared mode without blocking 🫢 Effectively calls mutex()->try_lock_shared().

std::system_error is thrown if there is no associated mutex or if the mutex is already locked. no cap, that's the whole vibe check πŸ’…


πŸŽ€ Parameters πŸŽ€

(none) β€” not a single parameter, bestie. zero. nada. πŸ“


✨ Return value ✨

true if the ownership of the mutex has been acquired successfully, false otherwise. periodt πŸ’–


πŸ’€ Exceptions πŸ’€

  • Any exceptions thrown by mutex()->try_lock_shared() β€” yes, whatever that throws, you get it 😭
  • If there is no associated mutex, std::system_error with an error code of std::errc::operation_not_permitted.
  • If the mutex is already locked, std::system_error with an error code of std::errc::resource_deadlock_would_occur.
bestie this is the β€œnot today” section, okay? if there's no associated mutex or it's already locked, std::system_error is coming for you πŸ’€βœ¨

🧚 Example 🧚

This section is incomplete Reason: no example

literally the manual page said β€œno example” and left it at that πŸ˜­πŸ™ˆ


πŸ¦‹ See also πŸ¦‹

  • lock β€” locks the associated mutex (public member function)
  • try_lock β€” tries to lock (i.e., takes ownership of) the associated mutex without blocking (public member function of std::unique_lock<Mutex>)
  • try_lock_for β€” tries to lock the associated mutex, for the specified duration (public member function)
  • try_lock_until β€” tries to lock the associated mutex, until a specified time point (public member function)
  • unlock β€” unlocks the associated mutex (public member function)

πŸ“ Category πŸ“

  • Todo no example

source: http://cppreference.com Β· version/date: 2024.06.10 Β· page tag: std::shared_lock::try_lock(3) β€” okay bye bestie, mwah πŸ’‹βœ¨πŸ¦‹

πŸ“¦ where this page comes from