[Prev] [Contents] [Next]

pthread_condattr_init()--Initialize Condition Variable Attributes Object

Syntax

#include <pthread.h>
int pthread_condattr_init(pthread_condattr_t *attr);
Threadsafe: Yes
Signal Safe: Yes

The pthread_condattr_init() function initializes the condition variable attributes object specified by attr to the default attributes. The condition variable attributes object is used to create condition variables with the pthread_cond_init() function.
Attribute Default value supported values
pshared PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED

Parameters

attr
(Output) The address of the variable to contain the condition variable attributes object

Authorities and Locks

None.

Return Value

0
pthread_condattr_init() was successful.
value
pthread_condattr_init() was not successful. value is set to indicate the error condition.

Error Conditions

If pthread_condattr_init() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.

[EINVAL]
The value specified for the argument is not correct.

Related Information

Example

#include <pthread.h>
#include <stdio.h>
#include "check.h"

pthread_cond_t      cond;

int main(int argc, char **argv)
{
  int                   rc=0;
  pthread_condattr_t    attr;

  printf("Entering testcase\n");

  printf("Create a default condition attribute\n");
  rc = pthread_condattr_init(&attr);
  checkResults("pthread_condattr_init\n", rc);

  printf("Create the condition using the condition attributes object\n");
  rc = pthread_cond_init(&cond, &attr);
  checkResults("pthread_cond_init()\n", rc);

  printf("- At this point, the condition with its default attributes\n");
  printf("- Can be used from any threads that want to use it\n");

  printf("Destroy cond attribute\n");
  rc = pthread_condattr_destroy(&attr);
  checkResults("pthread_condattr_destroy()\n", rc);
  
  printf("Destroy condition\n");
  rc = pthread_cond_destroy(&cond);
  checkResults("pthread_cond_destroy()\n", rc);
  
  printf("Main completed\n");
  return 0;
}
Output

Entering testcase
Create a default condition attribute
Create the condition using the condition attributes object
- At this point, the condition with its default attributes
- Can be used from any threads that want to use it
Destroy cond attribute
Destroy condition
Main completed


[Prev] [Contents] [Next]
Copyright © 1998, IBM Corporation. All rights reserved.
Comments? Contact
rchthrds@us.ibm.com