pthread_cond_init(3pthread)


pthread_cond_init, pthread_cond_destroy -- initialize or destroy a condition variable

Synopsis

cc [options] -Kthread file

#include <pthread.h>

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

Description

pthread_cond_init initializes the condition variable pointed to by cond with the attributes referenced by attr. If attr is NULL, the default condition variable attributes are used, which has the same effect as passing the address of a default condition variable attributes object. Once created, the condition cond can be used any number of times without being re-initialized.

pthread_cond_destroy destroys the condition variable cond. This includes invalidating cond and freeing any associated implementation-allocated dynamic resources.

When default condition attributes are appropriate, PTHREAD_COND_INITIALIZER can be used to initialize statically allocated condition variables. This is equivalent to dynamic initialization by a call to pthread_cond_init with attr set to NULL, but there is no error checking.

Return values

pthread_cond_init and pthread_cond_destroy return zero for success and an error number for failure.

Diagnostics

If the following conditions are detected, pthread_cond_init returns the corresponding value:

EINVAL
invalid attr argument specified
If the following conditions are detected, pthread_cond_destroy returns the corresponding value:

EBUSY
cond still has other threads waiting on it

EINVAL
invalid argument specified

Warnings

pthread_cond_init does not examine the cond argument before initializing it. If pthread_cond_init is called more than once for the same condition, it will overwrite its state. It is the user's responsibility to ensure that pthread_cond_init is only called once for each condition variable.

References

pthread_cond_broadcast(3pthread), pthread_cond_signal(3pthread), pthread_cond_timedwait(3pthread), pthread_cond_wait(3pthread)

Standards compliance

The Single UNIX Specification, Version 2; The Open Group.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004