Start of changepthread_cond_setname_np()--Set Name in Condition Variable


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

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_cond_setname_np() function sets the name of the condition variable specified by cond. The buffer specified by name must contain a null terminated string of 15 characters or less in length (not including the NULL). If the length of name is greater than 15 characters, the excess characters are ignored. If name is null, the condition variable name attribute is reset to the default.

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
(Input) Address of a null terminated character buffer containing the name

Authorities and Locks

None.


Return Value

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

Error Conditions

If pthread_cond_setname_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 set 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));
  strcpy(mutexName,"CONDITIONVAR1");
  printf("Set the name of the condition variable\n");
  rc = pthread_cond_setname_np(&cond, conditionVariableName);
  checkResults("pthread_cond_setname_np\n", rc);

  memset(conditionVariableName, 0, sizeof(conditionVariableName));
  printf("Get the name of the condition variable\n");
  rc = pthread_cond_getname_np(&cond, condVariableName);
  checkResults("pthread_cond_getname_np\n", rc);
  printf("The 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
Set the name of the condition variable
Get the name of the condition variable
The condition variable name is: CONDITIONVAR1
Destroy the condition variable
Main completed
End of change
API introduced: IBM® i 7.1

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