std::shared..._lock_until(3)
π 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 π
trueif the ownership of the mutex has been acquired successfullyfalseotherwise
π₯ EXCEPTIONS π₯
- any exceptions thrown by
mutex()->try_lock_shared_for(timeout_time) - if there is no associated mutex,
std::system_errorwith an error code ofstd::errc::operation_not_permitted - if the mutex is already locked,
std::system_errorwith an error code ofstd::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 ofstd::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
- 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