Name

pthread_cond_init
- create a condition variable

Library

libc_r.lib libpthread.lib libthr.lib

Synopsis

  #include <pthread.h>
  int pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t * attr);

Return values

If successful, the pthread_cond_init function will return zero and put the new condition variable id into cond, otherwise an error number will be returned to indicate the error.

Detailed description

The pthread_cond_init function creates a new condition variable referenced by cond with attributes referenced by attr. If attr is NULL, the default condition variable attributes shall be used; Upon successful initialization, the state of the condition variable shall become initialized.

Examples

int rc;
struct testdata
{
 pthread_mutex_t mutex;
 pthread_cond_t  cond;
};
static struct testdata td;
int function1()
{
 /* Initialize a condition variable object */
 if (pthread_cond_init(&td.cond, NULL) != 0) {
  fprintf(stderr,"Fail to initialize cond\n");
  return -1;
 }
 /* ... Use it for wait, signal, broadcast */
 /* Destroy the condition variable object */
 if((rc=pthread_cond_destroy(&td.cond)) != 0)
 {
   fprintf(stderr,"Error at pthread_cond_destroy(), rc=%d\n",rc);
   return -1;
 }
}

         

Errors

The pthread_cond_init function will fail if:
[EINVAL]
  The cond is NULL.

See also

pthread_cond_broadcast, pthread_cond_destroy, pthread_cond_signal, pthread_cond_timedwait, pthread_cond_wait

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top