Start of changepthread_attr_setname_np()--Set Thread Attributes Object Name


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

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_attr_setname_np() function sets the name attribute in the thread attribute object specified by attr. 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 thread name attribute is reset to the default.

By default, the name attribute in the thread attributes object is not set. A thread created using a thread attributes object that does not have the name attribute set will be unnamed. A thread name can be used by various system utilities to aid in debug and service. One example is the WRKJOB command, which has a `Work with threads' menu choice. On the 'Work with Threads' display, unnamed threads are identified only by a system-assigned number. It can be a difficult and time-consuming process to determine which thread is performing a specific function, or creating a particular problem. Naming the threads created by an application can greatly simplify problem analysis.

Note: This function is not portable.


Parameters

attr
(Input) Address of the thread attributes object
name
(Input) Address of a null terminated character buffer containing the name

Authorities and Locks

None.


Return Value

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

Error Conditions

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

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 ]