Home > pthread setname np not > pthread_setname_np error

Pthread_setname_np Error

Contents

char *name); int pthread_getname_np(pthread_t *thread, const char *name, size_t len); Compile and link with -pthread. Description By default, all the threads created using pthread_create() inherit the program name. The pthread_setname_np() function can be used to set a set thread name linux unique name for a thread, which can be useful for debugging multithreaded applications. pthread_setname_np not found The thread name is a meaningful C language string, whose length is restricted to 16 characters, including the terminating implicit declaration of function ‘pthread_setname_np’ null byte. The thread argument specifies the thread whose name is to be changed; name specifies the new name. The pthread_getname_np() function can be used to retrieve the name of the thread.

Pthread_getname_np

The thread argument specifies the thread whose name is to be retrieved. The buffer name is used to return the thread name; len specifies the number of bytes available in name. The buffer specified by name should be at least 16 characters in length. The returned thread name in the output buffer will be null terminated. Return Value On success, these functions return 0; on pthread_getname_np example error, they return a nonzero error number. Errors The pthread_setname_np() function can fail with the following error: ERANGE The length of the string specified pointed to by name exceeds the allowed limit. The pthread_getname_np() function can fail with the following error: ERANGE The buffer specified by name and len is too small to hold the thread name. If either of these functions fails to open /proc/self/task/[tid]/comm, then the call may fail with one of the errors described in open(2). Versions These functions first appeared in glibc in version 2.12. Conforming To These functions are nonstandard GNU extensions. Notes pthread_setname_np() internally writes to the thread specific comm file under /proc filesystem: /proc/self/task/[tid]/comm. pthread_getname_np() retrieves it from the same location. Example The program below demonstrates the use of pthread_setname_np() and pthread_getname_np(). The following shell session shows a sample run of the program: $ ./a.out Created a thread. Default name is: a.out The thread name after setting it is THREADFOO. ^Z # Suspend the program [1]+ Stopped ./a.out $ ps H -C a.out -o 'pid tid cmd comm' PID TID CMD COMMAND 5990 5990 ./a.out a.out 5990 5991 ./a.out THREADFOO $ cat /proc/5990/task/5990/com

or a NULL-terminated string that specifies the new name. The maximum length is http://www.qnx.com/developers/docs/6.5.0SP1.update/com.qnx.doc.neutrino_lib_ref/p/pthread_setname_np.html _NTO_THREAD_NAME_MAX (defined in ). Library: libc Use the -l c option to qcc to link against this library. This library is usually included https://ghc.haskell.org/trac/ghc/ticket/9684 automatically. Description: (QNX Neutrino Core OS 6.3.2 or later) The pthread_setname_np() function sets the name of the specified thread to newname. If newname is pthread_setname_np not NULL, the function deletes any name already assigned to the thread. The "np" in the function's name stands for "non-POSIX." 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 set thread name 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. Returns: EOK Success. E2BIG The name is too long. EBUSY 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. EPERM You don't have the appropriate permissions to set the name. Classification: QNX Neutrino Safety: Cancellation point Yes Interrupt handler No Signal handler Yes Thread Yes See also: pthread_getname_np(), ThreadCtl() "Controlling processes via the /proc filesystem" in the Processes chapter of the QNX Neutrino Programmer's Guide

Lists & IRC The GHC Team   Documentation GHC Status Info Building Guide Working conventions Commentary Debugging Infrastructure   View Tickets My Tickets Tickets I Created By Milestone By OS By Architecture Patches for review   Create Ticket New Bug New Task New Feature Req   Wiki Title Index Recent Changes Wiki Notes Opened 2 years ago Closed 2 years ago #9684 closed bug (fixed) Broken build on OS X (incompatible pthread_setname_np API) Reported by: mlen Owned by: Priority: normal Milestone: Component: Compiler Version: 7.9 Keywords: pthread_setname_np Cc: hvr, simonmar, rodlogic Operating System: MacOS X Architecture: Unknown/Multiple Type of failure: Building GHC failed Test Case: Blocked By: Blocking: Related Tickets: Differential Rev(s): ​Phab:rGHC674c631ea111233daa929ef63500d75ba0db8858, ​Phab:D338 Wiki Page: Description Build is broken on OS X because it is only possible to set thread name for the current thread and pthread_setname_np accepts a single argument. This function appeared in 10.6. If that OS version needs to be supported, the best thing that can be done is conditional compilation. A short summary of inconsistencies between different *nix systems can be found here: ​http://stackoverflow.com/questions/2369738/can-i-set-the-name-of-a-thread-in-pthreads-linux/7989973#7989973 The error log: rts/posix/OSThreads.c:138:30: error: too many arguments to function call, expected 1, have 2 pthread_setname_np(*pId, name); ~~~~~~~~~~~~~~~~~~ ^~~~ /usr/include/pthread.h:471:1: note: 'pthread_setname_np' declared here __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) ^ /usr/include/Availability.h:159:50: note: expanded from macro '__OSX_AVAILABLE_STARTING' #define __OSX_AVAILABLE_STARTING(_osx, _ios) __AVAILABILITY_INTERNAL##_osx ^ :65:1: note: expanded from here __AVAILABILITY_INTERNAL__MAC_10_6 ^ /usr/include/AvailabilityInternal.h:3912:72: note: expanded from macro '__AVAILABILITY_INTERNAL__MAC_10_6' #define __AVAILABILITY_INTERNAL__MAC_10_6 __attribute__((availability(macosx,introduced=10.6))) ^ 1 error generated. I can see two possible solutions for OS X: disable setting thread name by conditional compilation. write some trampoline code to work around the fact that it is only possible to set thread name for the current thread. The latter would look like this: struct wrapper { char *name; void *param; void *(*cont)(void *); }; void *trampoline(void *ctx) { struct wrapper *params = (struct wrapper *)ctx; void *param = params->p

 

Related content

No related pages.