다음을 통해 공유


condition_variable_any 클래스

condition_variable_any 클래스를 사용하여 모든 mutex 형식의 이벤트를 대기합니다.

구문

class condition_variable_any;

멤버

생성자

이름 설명
condition_variable_any condition_variable_any 개체를 생성합니다.

함수

속성 설명
notify_all condition_variable_any 개체를 대기 중인 모든 스레드를 차단 해제합니다.
notify_one condition_variable_any 개체를 대기 중인 스레드 중 하나를 차단 해제합니다.
wait 스레드를 차단합니다.
wait_for 스레드를 차단하고 스레드가 차단 해제되는 시간 간격을 설정합니다.
wait_until 스레드를 차단하고 스레드가 차단 해제되는 최대 시점을 설정합니다.

condition_variable_any

condition_variable_any 개체를 생성합니다.

condition_variable_any();

설명

메모리가 부족한 경우 생성자에서 not_enough_memory 오류 코드가 있는 system_error 개체를 throw합니다. 몇 가지 다른 리소스를 사용할 수 없기 때문에 개체를 생성할 수 없는 경우 생성자에서 resource_unavailable_try_again 오류 코드가 있는 system_error 개체를 throw합니다.

notify_all

condition_variable_any 개체를 대기 중인 모든 스레드를 차단 해제합니다.

void notify_all() noexcept;

notify_one

condition_variable_any 개체를 기다리는 스레드 중 하나를 차단 해제합니다.

void notify_one() noexcept;

wait

스레드를 차단합니다.

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

template <class Lock, class Predicate>
void wait(Lock& Lck, Predicate Pred);

매개 변수

.lck
모든 형식의 mutex 개체입니다.

Pred
true 또는 false를 반환하는 모든 식입니다.

설명

첫 번째 메서드는 condition_variable_any 개체에서 notify_one 또는 notify_all에 대한 호출을 통해 신호를 받을 때까지 차단합니다. 또한 의사적으로 대기 모드를 해제할 수도 있습니다.

두 번째 메서드는 실제로 다음 코드를 실행합니다.

while (!Pred())
    wait(Lck);

wait_for

스레드를 차단하고 스레드가 차단 해제되는 시간 간격을 설정합니다.

template <class Lock, class Rep, class Period>
bool wait_for(Lock& Lck, const chrono::duration<Rep, Period>& Rel_time);

template <class Lock, class Rep, class Period, class Predicate>
bool wait_for(Lock& Lck, const chrono::duration<Rep, Period>& Rel_time, Predicate Pred);

매개 변수

.lck
모든 형식의 mutex 개체입니다.

Rel_time
스레드가 대기 모드를 해제하기 전까지의 시간을 지정하는 chrono::duration 개체입니다.

Pred
true 또는 false를 반환하는 모든 식입니다.

Return Value

첫 번째 메서드는 Rel_time 경과했을 때 대기가 종료되는 경우 반환 cv_status::timeout 됩니다. 그렇지 않은 경우 메서드는 cv_status::no_timeout를 반환합니다.

두 번째 메서드는 Pred값을 반환합니다.

설명

첫 번째 메서드는 개체가 condition_variable_any notify_one 또는 notify_all 호출로 신호를 받거나 시간 간격 Rel_time 경과할 때까지 차단됩니다. 또한 의사적으로 대기 모드를 해제할 수도 있습니다.

두 번째 메서드는 실제로 다음 코드를 실행합니다.

while(!Pred())
    if(wait_for(Lck, Rel_time) == cv_status::timeout)
    return Pred();

return true;

wait_until

스레드를 차단하고 스레드가 차단 해제되는 최대 시점을 설정합니다.

template <class Lock, class Clock, class Duration>
void wait_until(Lock& Lck, const chrono::time_point<Clock, Duration>& Abs_time);

template <class Lock, class Clock, class Duration, class Predicate>
void wait_until(
    Lock& Lck,
    const chrono::time_point<Clock, Duration>& Abs_time,
    Predicate Pred);

template <class Lock>
void wait_until(Lock Lck, const xtime* Abs_time);

template <class Lock, class Predicate>
void wait_until(
    Lock Lck,
    const xtime* Abs_time,
    Predicate Pred);

매개 변수

.lck
뮤텍스 개체입니다.

Abs_time
chrono::time_point 개체입니다.

Pred
true 또는 false를 반환하는 모든 식입니다.

Return Value

Abs_time 경과할 때 대기가 종료되는 경우 형식 반환을 반환 cv_statuscv_status::timeout 하는 메서드입니다. 그렇지 않으면 메서드는 cv_status::no_timeout을 반환합니다.

Pred 값을 반환 bool 하는 메서드입니다.

설명

첫 번째 메서드는 개체가 condition_variable notify_one 또는 notify_all 호출에 의해 신호를 받거나 Abs_time 때까지 차단됩니다. 또한 의사적으로 대기 모드를 해제할 수도 있습니다.

두 번째 메서드는 실제로 다음 코드를 실행합니다.

while(!Pred())
    if(wait_until(Lck, Abs_time) == cv_status::timeout)
    return Pred();

return true;

세 번째와 네 번째 메서드는 xtime 형식의 개체에 대한 포인터를 사용하여 chrono::time_point 개체를 대체합니다. xtime 개체는 신호를 기다리는 최대 시간을 지정합니다.