std::unique..._lock_until(3)

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

✨ NAME ✨

okay so this page is std::unique..._lock_until(3), and it lives in the C++ Standard Libary manual β€” yes, that’s the manual name, spelling and all, don’t come for me πŸ’…. The actual thing being documented is std::unique_lock::try_lock_until, and the NAME line is literally matching itself: std::unique_lock::try_lock_until - std::unique_lock::try_lock_until. iconic self-reference, no cap πŸŽ€.


πŸ¦‹ Synopsis πŸ¦‹

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

the (since C++11) bit is a version tag, bestie β€” don’t try to pass it as an argument 😭.

So what does it do? It tries to lock (i.e., takes ownership of) the associated mutex. 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. Heads up: it may block for longer than timeout_time until has been reached. 🫢

It effectively calls mutex()->try_lock_until(timeout_time).

std::system_error is thrown if there is no associated mutex or if the mutex is already locked by the same thread.

Clock must meet the Clock requirements. The program is ill-formed if std::chrono::is_clock_v<Clock> is false. (since C++20) ⭐


🌸 Parameters 🌸

  • timeout_time β€” maximum time point to block until πŸ’–

πŸŽ€ Return value πŸŽ€

true if the ownership of the mutex has been acquired successfully, false otherwise. periodt.


πŸ”₯ Exceptions πŸ”₯

  • Any exceptions thrown by mutex()->try_lock_until(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.
okay but fr fr, that second and third bullet are the β€œsomething is not giving” errors β€” clock them before they clock you πŸ’€

🧚 Example 🧚

This section is incomplete. Reason: no example.

not me showing up with an example-less section πŸ˜­πŸ™ˆ β€” but that’s literally what the page says.


πŸ‘‘ See also πŸ‘‘

  • lock β€” locks (i.e., takes ownership of) the associated mutex (public member function)
  • try_lock β€” tries to lock (i.e., takes ownership of) the associated mutex without blocking (public member function)
  • try_lock_for β€” attempts to lock (i.e., takes ownership of) the associated TimedLockable mutex, returns if the mutex has been unavailable for the specified time duration (public member function)
  • unlock β€” unlocks (i.e., releases ownership of) the associated mutex (public member function)

all the little lock besties, linked and living their truth ✨


🌈 Category 🌈

  • Todo no example

πŸ’– xoxo, bestie β€” source: cppreference.com, version/date: 2024.06.10, and yes this is still the std::unique..._lock_until(3) page πŸŽ€

πŸ“¦ where this page comes from