pthread_cond_init(),
pthread_cond_signal(),
pthread_cond_wait()
int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr);
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
int pthread_cond_signal(pthread_cond_t *cond);
int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex);
Example:
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
// some thread, waiting:
Pthread_mutex_lock(&lock);
while (ready == 0) Pthread_cond_wait(&cond, &lock);
// condition occurred and we have the lock here
... do stuff ...
Pthread_mutex_unlock(&lock);
// some other thread, signaling:
Pthread_mutex_lock(&lock);
... do stuff ...
ready = 1;
Pthread_cond_signal(&cond);
Pthread_mutex_unlock(&lock);