Creates a condition variable.
Syntax
pthread_cond_init(
cond,
attr );
Argument Data Type Access
cond opaque pthread_cond_t write
attr opaque pthread_ read
condattr_t
C Binding
int
pthread_cond_init (
pthread_cond_t *cond,
pthread_condattr_t attr);
Arguments
- cond
- Condition variable that is created.
- attr
- Condition variable attributes object that defines the
characteristics of the condition variable created. If you specify
pthread_condattr_default, default attributes are used.
Description
This routine creates and initializes a condition variable. A
condition variable is a synchronization object used in conjunction
with a mutex. A mutex controls access to shared data; a condition
variable allows threads to wait for that data to enter a defined
state.
Condition variables are not owned by a particular thread. Any
associated storage is not automatically deallocated when the
creating thread terminates.
Return Values
If an error condition occurs, this routine returns -1, the condition
variable is not initialized, and the contents of cond are
undefined. This routine sets errno to the corresponding
error value. Possible return values are as follows:
Return Error Description
0 Successful completion.
-1 [EAGAIN] The system lacks the necessary resources to
initialize another condition variable.
The system-imposed limit on the total number
of condition variables under execution by a
single user is exceeded.
-1 [ENOMEM] Insufficient memory exists to initialize the
condition variable.