#include <pthread.h> int pthread_attr_setname_np(pthread_attr_t *attr, const char *name);Service Program Name: QP0WPTHR
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.
None.
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] |
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
[ Back to top | Pthread APIs | APIs by category ]