Start of changepthread_attr_getname_np()--Get Thread Attributes Name


  Syntax
       #include <pthread.h>
       int pthread_attr_getname_np(const pthread_attr_t *attr, char *name);
  Service Program Name: QP0WPTHR

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_attr_getname_np() function returns the name attribute from the thread attributes object specified. 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 thread attributes object is unnamed. If the pthread_attr_setname_np() function has not been used to set the name of the specified thread attributes object, a null string is retrieved into name.

Note: This function is not portable.


Parameters

attr
(Input) Address of the thread attributes object
name
(Output) Address of a 16-byte character buffer to receive the thread name

Authorities and Locks

None.


Return Value

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

Error Conditions

If pthread_attr_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

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 <string.h>

int main(int argc, char **argv)
{
  pthread_attr_t        threadAttr;
  pthread_t             thread;
  int                   rc=0;
  char                  theName[16];

  rc = pthread_attr_init(&threadAttr);
  if (0 != rc)
  {
    printf("Error initializing thread attributes - %d\n",rc);
    return(rc);
  }
  memset(theName, 0x00, sizeof(theName));
  rc = pthread_attr_setname_np(&threadAttr, "THREADNAMEISTOOLONG");
  if(0 == rc)
  {
    rc = pthread_attr_getname_np(&threadAttr, theName);
    if(0 == rc)
    {
      printf("The thread attributes object name is %s.\n", theName);
    }
  }
  printf("Main completed\n");
  return(rc);
}

Example Output:
The thread attributes object name is THREADNAMEISTOO.
Main completed
End of change
API introduced: IBM® i 7.1

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