OpenBSD manual page server

Manual Page Search Parameters

PTHREAD_COND_INIT(3) Library Functions Manual PTHREAD_COND_INIT(3)

pthread_cond_init, pthread_cond_destroy, pthread_cond_wait, pthread_cond_timedwait, pthread_cond_broadcast, pthread_cond_signalblock and unblock threads with condition variables

/* -lpthread */
#include <pthread.h>

int
pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);

int
pthread_cond_destroy(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_broadcast(pthread_cond_t *cond);

int
pthread_cond_signal(pthread_cond_t *cond);

The () function creates a new condition variable with attributes specified by attr. If attr is NULL, the default attributes are used.

The () function frees the resources associated with the condition variable cond.

The () function atomically blocks the current thread by waiting on the condition variable cond, and unlocks the mutex specified by mutex. The waiting thread unblocks only after another thread calls pthread_cond_broadcast() or pthread_cond_signal() with the same condition variable. The () function does the same, but returns after the system time reaches abstime. In all cases, both functions then reacquire the lock on mutex before returning.

The () function unblocks all threads waiting for the condition variable cond. The () function unblocks at least one thread waiting for the condition variable cond.

These functions return zero for success and positive error numbers for failure.

pthread_cond_init() fails if:

[]
The value specified by attr is invalid.
[]
The process cannot allocate enough memory to create another condition variable.
[]
The system temporarily lacks the resources to create another condition variable.

The other functions fail if:

[]
The value specified by cond, mutex, or abstime is invalid.

pthread_cond_destroy() additionally fails if:

[]
The variable cond is locked by another thread.

pthread_cond_timedwait() additionally fails if:

[]
The system time has reached or exceeded the time specified in abstime.

pthread_condattr_init(3), pthread_mutex_init(3)

These functions conform to ISO/IEC 9945-1:1996 (“POSIX.1”).

July 3, 2025 OpenBSD-current