pthread_mutex_getname_np()--Get Name from Mutex
Syntax
#include <pthread.h> int pthread_mutex_getname_np(pthread_mutex_t *mutex, char *name);Service Program Name: QP0WPTHR
Default Public Authority: *USE
Threadsafe: Yes
Signal Safe: Yes
The pthread_mutex_getname_np() function retrieves the name of the specified mutex. The buffer specified by name must be at least 16 characters in length. The returned mutex name will be null terminated in the output buffer.
By default, each pthread_mutex_t has the name "QP0WMTX UNNAMED" associated with it. The name attribute is used by various IBM i system utilities to aid in debug and service. One example is the WRKJOB command, which has a `work with mutexes' menu choice to show which mutexes are currently locked and which mutexes are being waited for.
You should give unique names to all mutexes created to aid in debugging deadlock or performance problems. Use the CL command WRKJOB, option 20, to help debug mutex deadlocks.
Note: This function is not portable.
Parameters
- mutex
- (Input) The address of the mutex object
- name
- (Output) Address of 16 byte buffer to receive the name
Authorities and Locks
None.
Return Value
- 0
- pthread_mutex_getname_np() was successful.
- value
- pthread_mutex_getname_np() was not successful. value is set to indicate the error condition.
Error Conditions
If pthread_mutex_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] |
Related Information
- The <pthread.h> header file. See Header files for Pthread functions.
- pthread_mutex_setname_np()--Set Name in Mutex
- pthread_mutex_init()--Initialize Mutex
- pthread_mutex_destroy()--Destroy Mutex
Example
The following example will get the mutex name.
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 <errno.h> #include "check.h" pthread_mutex_t mutex; int main(int argc, char **argv) { int rc=0; pthread_mutexattr_t mta; char mutexName[16]; printf("Enter Testcase - %s\n", argv[0]); printf("Create a default mutex attribute\n"); rc = pthread_mutexattr_init(&mta); checkResults("pthread_mutexattr_init\n", rc); printf("Create the mutex using a mutex attributes object\n"); rc = pthread_mutex_init(&mutex2, &mta); checkResults("pthread_mutex_init(mta)\n", rc); memset(mutexName, 0, sizeof(mutexName)); printf("Get the default name of the mutex\n"); rc = pthread_mutex_getname_np(&mutex, mutexName); checkResults("pthread_mutex_getname_np\n", rc); printf("The default mutex name is: %.15s\n", mutexName); printf("Destroy the mutex\n"); pthread_mutex_destroy(&mutex); printf("Main completed\n"); return 0; }Example Output:
Enter Testcase - QP0WTEST/TPCRT0 Create a default mutex attribute Create the mutex using a mutex attributes object Get the default name of the mutex The default mutex name is: QP0WMTX UNNAMED Destroy the mutex Main completed
API introduced: IBM® i 7.1
[ Back to top | Pthread APIs | APIs by category ]