std::shared..._lock_until(3)

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

πŸ’… std::shared_lock::try_lock_until β€” C++ Standard Libary, bestie edition ✨

okay so bestie, welcome to the <shared_mutex>-adjacent corner of the C++ Standard Libary (yes that's how it's spelled on the page, we don't fix, we respect 🫢) β€” this is the manual page for std::shared_lock::try_lock_until, and it's genuinely iconic once you get past the syntax jumpscare. let's go 🌈


✨ SYNOPSIS ✨

template< class Clock, class Duration >
bool try_lock_until( const std::chrono::time_point<Clock,Duration>&
(since C++14)
     timeout_time );

so what this does is β€” it tries to lock the associated mutex in shared mode. it blocks until the specified timeout_time has been reached or the lock is acquired, whichever comes first. on successful lock acquisition it returns true, otherwise it returns false. and ngl, it may block for longer than until timeout_time has been reached β€” like, it's not gonna teleport out the exact nanosecond, okay? 😭

effectively, it calls:

mutex()->try_lock_shared_until(timeout_time)

std::system_error is thrown if there's no associated mutex or if the mutex is already locked. periodt.

Clock must meet the Clock requirements. the behavior is undefined if Mutex does not meet the SharedTimedLockable requirements. (read that again, bestie β€” undefined, not "oopsie, returns false" πŸ’€)

and since C++20: the program is ill-formed if std::chrono::is_clock_v<Clock> is false. so like, don't do that πŸ™ˆ


πŸŽ€ PARAMETERS πŸŽ€

  • timeout_time β€” the maximum time point to block until

πŸ’– RETURN VALUE πŸ’–

  • true if the ownership of the mutex has been acquired successfully
  • false otherwise

πŸ”₯ EXCEPTIONS πŸ”₯

  • any exceptions thrown by mutex()->try_lock_shared_for(timeout_time)
  • 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
not me double-checking that first bullet β€” yes, the page literally says try_lock_shared_for(timeout_time) right there under exceptions, so it goes in verbatim, exactly character for character. we copy, we don't correct πŸ’…

πŸ¦‹ EXAMPLE πŸ¦‹

this section is incomplete 😭

reason: no example

(lowkey tragic, highkey relatable β€” the docs said "figure it out yourself bestie")


πŸ‘‘ SEE ALSO πŸ‘‘

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

πŸ“ CATEGORY πŸ“

  • Todo no example

alright that's the whole page, you ate it up 🌸 β€” source http://cppreference.com, version dated 2024.06.10, and this whole std::shared..._lock_until(3) situation is officially signed, sealed, and slayed πŸŽ€βœ¨πŸ’œ

πŸ“¦ where this page comes from