pthread_cond_init(3) Library Functions Manual pthread_cond_init(3) pthread_cond_init, pthread_cond_signal, pthread_cond_broadcast, pthread_cond_wait, pthread_cond_timedwait, pthread_cond_destroy - #include pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr); int pthread_cond_signal(pthread_cond_t *cond); int pthread_cond_broadcast(pthread_cond_t *cond); int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime); int pthread_cond_destroy(pthread_cond_t *cond); ( " ") . : ( ) . (mutex) . pthread_cond_init() cond cond_attr cond_attr (NULL). LinuxThreads cond_attr . pthread_cond_t PTHREAD_COND_INITIALIZER. pthread_cond_signal() cond. cond . cond . pthread_cond_broadcast() cond. cond. pthread_cond_wait() mutex ( pthread_mutex_unlock()) cond. . mutex pthread_cond_wait(). pthread_cond_wait() mutex ( pthread_mutex_lock()). . ( ) . . pthread_cond_timedwait() mutex cond pthread_cond_wait() . cond abstime mutex pthread_cond_timedwait() ETIMEDOUT. abstime time(2) gettimeofday(2): abstime 0 00:00:00 1 1970. pthread_cond_destroy() . pthread_cond_destroy(). LinuxThreads pthread_cond_destroy() . pthread_cond_wait() pthread_cond_timedwait() . mutex pthread_cond_wait() pthread_cond_timedwait() . mutex . . pthread_cond_signal() pthread_cond_broadcast() (deadlock). 0 . pthread_cond_init() pthread_cond_signal() pthread_cond_broadcast() pthread_cond_wait() . pthread_cond_timedwait() : ETIMEDOUT abstime. pthread_cond_destroy() : EBUSY cond. pthread_condattr_init(3) pthread_mutex_lock(3) pthread_mutex_unlock(3) gettimeofday(2) nanosleep(2). glibc 2.25 . . glibc 2.25 . pthread_cond_signal() pthread_cond_broadcast(). . ETIMEDOUTA EINTR. x y mut cond x y. int x,y; pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; x y : pthread_mutex_lock(&mut); while (x <= y) { pthread_cond_wait(&cond, &mut); } /* operate on x and y */ pthread_mutex_unlock(&mut); x y x y : pthread_mutex_lock(&mut); /* modify x and y */ if (x > y) pthread_cond_broadcast(&cond); pthread_mutex_unlock(&mut); ( x y) pthread_cond_signal() pthread_cond_broadcast(). pthread_cond_broadcast(). x y 5 : struct timeval now; struct timespec timeout; int retcode; pthread_mutex_lock(&mut); gettimeofday(&now); timeout.tv_sec = now.tv_sec + 5; timeout.tv_nsec = now.tv_usec * 1000; retcode = 0; while (x <= y && retcode != ETIMEDOUT) { retcode = pthread_cond_timedwait(&cond, &mut, &timeout); } if (retcode == ETIMEDOUT) { /* timeout occurred */ } else { /* operate on x and y */ } pthread_mutex_unlock(&mut); 3 . . : . 6.18 22 2026 pthread_cond_init(3)