Files
2025-10-25 03:02:53 +03:00

7.1 KiB
Raw Permalink Blame History

[thread.condvarany.wait]

32 Concurrency support library [thread]

32.7 Condition variables [thread.condition]

32.7.5 Class condition_variable_any [thread.condition.condvarany]

32.7.5.2 Noninterruptible waits [thread.condvarany.wait]

🔗

template<class Lock> void wait(Lock& lock);

1

#

Effects:

  • (1.1)

    Atomically calls lock.unlock() and blocks on *this.

  • (1.2)

    When unblocked, calls lock.lock() (possibly blocking on the lock) and returns.

  • (1.3)

    The function will unblock when signaled by a call to notify_one(), a call to notify_all(), or spuriously.

2

#

Postconditions: lock is locked by the calling thread.

3

#

Throws: Nothing.

4

#

Remarks: If the function fails to meet the postcondition, terminate() is invoked ([except.terminate]).

[Note 1:

This can happen if the re-locking of the mutex throws an exception.

— end note]

🔗

template<class Lock, class Predicate> void wait(Lock& lock, Predicate pred);

5

#

Effects: Equivalent to:while (!pred()) wait(lock);

🔗

template<class Lock, class Clock, class Duration> cv_status wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time);

6

#

Effects:

  • (6.1)

    Atomically calls lock.unlock() and blocks on *this.

  • (6.2)

    When unblocked, calls lock.lock() (possibly blocking on the lock) and returns.

  • (6.3)

    The function will unblock when signaled by a call to notify_one(), a call to notify_all(), expiration of the absolute timeout ([thread.req.timing]) specified by abs_time, or spuriously.

  • (6.4)

    If the function exits via an exception, lock.lock() is called prior to exiting the function.

7

#

Postconditions: lock is locked by the calling thread.

8

#

Returns: cv_status::timeout if the absolute timeout ([thread.req.timing]) specified by abs_time expired, otherwise cv_status::no_timeout.

9

#

Throws: Timeout-related exceptions ([thread.req.timing]).

10

#

Remarks: If the function fails to meet the postcondition, terminate() is invoked ([except.terminate]).

[Note 2:

This can happen if the re-locking of the mutex throws an exception.

— end note]

🔗

template<class Lock, class Rep, class Period> cv_status wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time);

11

#

Effects: Equivalent to:return wait_until(lock, chrono::steady_clock::now() + rel_time);

12

#

Postconditions: lock is locked by the calling thread.

13

#

Returns: cv_status::timeout if the relative timeout ([thread.req.timing]) specified by rel_time expired, otherwise cv_status::no_timeout.

14

#

Throws: Timeout-related exceptions ([thread.req.timing]).

15

#

Remarks: If the function fails to meet the postcondition, terminate is invoked ([except.terminate]).

[Note 3:

This can happen if the re-locking of the mutex throws an exception.

— end note]

🔗

template<class Lock, class Clock, class Duration, class Predicate> bool wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time, Predicate pred);

16

#

Effects: Equivalent to:while (!pred())if (wait_until(lock, abs_time) == cv_status::timeout)return pred();return true;

17

#

[Note 4:

There is no blocking if pred() is initially true, or if the timeout has already expired.

— end note]

18

#

[Note 5:

The returned value indicates whether the predicate evaluates to true regardless of whether the timeout was triggered.

— end note]

🔗

template<class Lock, class Rep, class Period, class Predicate> bool wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred);

19

#

Effects: Equivalent to:return wait_until(lock, chrono::steady_clock::now() + rel_time, std::move(pred));