Start of changepthread_cond_getname_np()--Get Name of Condition Variable


  Syntax
 #include <pthread.h>
 int pthread_cond_getname_np(pthread_cond_t *cond,
                             char *name);
  Service Program Name: QP0WPTHR

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_cond_getname_np() function retrieves the name of the condition variable specified by cond. The buffer specified by name must be at least 16 characters in length. The returned thread name will be null terminated in the output buffer.

By default, each pthread_cond_t has the name "PTHREAD_COND" associated with it.

Note: This function is not portable.


Parameters

cond
(Input) The address of the condition variable object
name
(Output) Address of 16 byte buffer to receive the name

Authorities and Locks

None.


Return Value

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

Error Conditions

If pthread_cond_getname_np() 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.

Error condition Additional information
[EINVAL]  


Usage Notes


Related Information


Example

The following example will get the condition variable name.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include "check.h"

pthread_cond_t    cond;

int main(int argc, char **argv)
{
  int                   rc=0;
  pthread_condattr_t    cta;
  char conditionVariableName[16];

  printf("Enter Testcase - %s\n", argv[0]);

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

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

  memset(conditionVariableName, 0, sizeof(conditionVariableName));
  printf("Get the default name of the condition variable\n");
  rc = pthread_cond_getname_np(&cond, conditionVariableName);
  checkResults("pthread_cond_getname_np\n", rc);
  printf("The default condition variable name is: %.15s\n", conditionVariableName);

  printf("Destroy the condition variable\n");
  pthread_cond_destroy(&cond);

  printf("Main completed\n");
  return 0;
}

Example Output:
Enter Testcase - QP0WTEST/TPCRT0
Create a default condition variable attribute
Create the condition variable using a condition variable attributes object
Get the default name of the condition variable
The default condition variable name is: PTHREAD_COND
Destroy the condition variable
Main completed
End of change
API introduced: IBM® i 7.1

[ Back to top | Pthread APIs | APIs by category ]