A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://timsong-cpp.github.io/cppwp/n4659/thread.condition.condvar below:

[thread.condition.condvar]

33 Thread support library [thread] 33.5 Condition variables [thread.condition] 33.5.3 Class condition_­variable [thread.condition.condvar]
namespace std {
  class condition_variable {
  public:

    condition_variable();
    ~condition_variable();

    condition_variable(const condition_variable&) = delete;
    condition_variable& operator=(const condition_variable&) = delete;

    void notify_one() noexcept;
    void notify_all() noexcept;
    void wait(unique_lock<mutex>& lock);
    template <class Predicate>
      void wait(unique_lock<mutex>& lock, Predicate pred);
    template <class Clock, class Duration>
      cv_status wait_until(unique_lock<mutex>& lock,
                           const chrono::time_point<Clock, Duration>& abs_time);
    template <class Clock, class Duration, class Predicate>
      bool wait_until(unique_lock<mutex>& lock,
                      const chrono::time_point<Clock, Duration>& abs_time,
                      Predicate pred);

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

    using native_handle_type = implementation-defined;     native_handle_type native_handle();                  };
}

The class condition_­variable shall be a standard-layout class (Clause [class]).

condition_variable();

Effects: Constructs an object of type condition_­variable.

Error conditions:

~condition_variable();

Requires: There shall be no thread blocked on *this. [Note: That is, all threads shall have been notified; they may subsequently block on the lock specified in the wait. This relaxes the usual rules, which would have required all wait calls to happen before destruction. Only the notification to unblock the wait must happen before destruction. The user must take care to ensure that no threads wait on *this once the destructor has been started, especially when the waiting threads are calling the wait functions in a loop or using the overloads of wait, wait_­for, or wait_­until that take a predicate. end note]

Effects: Destroys the object.

void notify_one() noexcept;

Effects: If any threads are blocked waiting for *this, unblocks one of those threads.

void notify_all() noexcept;

Effects: Unblocks all threads that are blocked waiting for *this.

void wait(unique_lock<mutex>& lock);

Requires: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread, and either

Effects:

Remarks: If the function fails to meet the postcondition, terminate() shall be called ([except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. end note]

Postconditions: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread.

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

Requires: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread, and either

Effects: Equivalent to:

while (!pred())
  wait(lock);

Remarks: If the function fails to meet the postcondition, terminate() shall be called ([except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. end note]

Postconditions: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread.

Throws: Any exception thrown by pred.

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

Requires: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread, and either

Effects:

Remarks: If the function fails to meet the postcondition, terminate() shall be called ([except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. end note]

Postconditions: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread.

Returns: cv_­status​::​timeout if the absolute timeout ([thread.req.timing]) specified by abs_­time expired, otherwise cv_­status​::​no_­timeout.

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

Requires: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread, and either

Effects: Equivalent to:

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

Returns: cv_­status​::​timeout if the relative timeout ([thread.req.timing]) specified by rel_­time expired, otherwise cv_­status​::​no_­timeout.

Remarks: If the function fails to meet the postcondition, terminate() shall be called ([except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. end note]

Postconditions: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread.

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

Requires: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread, and either

Effects: Equivalent to:

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

Remarks: If the function fails to meet the postcondition, terminate() shall be called ([except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. end note]

Postconditions: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread.

[Note: The returned value indicates whether the predicate evaluated to true regardless of whether the timeout was triggered. end note]

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

Requires: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread, and either

Effects: Equivalent to:

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

[Note: There is no blocking if pred() is initially true, even if the timeout has already expired. end note]

Remarks: If the function fails to meet the postcondition, terminate() shall be called ([except.terminate]). [Note: This can happen if the re-locking of the mutex throws an exception. end note]

Postconditions: lock.owns_­lock() is true and lock.mutex() is locked by the calling thread.

[Note: The returned value indicates whether the predicate evaluates to true regardless of whether the timeout was triggered. end note]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4