Name a thread
#include <pthread.h> int pthread_setname_np(pthread_t tid, const char* newname);
- The ID of the thread you want to name, or 0 if you want to name the calling thread.
- NULL, or a NULL-terminated string that specifies the new name. The maximum length is _NTO_THREAD_NAME_MAX (defined in <sys/neutrino.h>).
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The pthread_setname_np() function sets the name of the specified thread to newname. If newname is NULL, the function deletes any name already assigned to the thread. The np in the function's name stands for non-POSIX.
This function is currently implemented as follows:
- If a thread is setting its own name, pthread_setname_np() uses ThreadCtl().
- If a thread is setting another thread's name, pthread_setname_np() needs read/write access to the /proc/pid/as entry for the process.
Only one program can have write access to the a process's entry in the /proc filesystem at a time, so if another program (such as a debugger) already has write access to it, pthread_setname_np() fails with an error of EBUSY. For this reason, it's better to have a thread set its own name than have it set by another thread.
- The name is too long.
- As described above, you're trying to name a thread other than the calling thread, and another program already has write access to /proc/pid/as.
- You don't have the appropriate permissions to set the name.