#include <pthread.h> int pthread_rwlock_setname_np(pthread_rwlock_t *rwlock, const char *name);Service Program Name: QP0WPTHR
The pthread_rwlock_setname_np() function sets the name of the read/write lock specified by rwlock. 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 read/write lock name is reset to the default.
By default, each pthread_rwlock_t does not have a name associated with it.
Note: This function is not portable.
None.
If pthread_rwlock_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] |
The following example will set the read/write lock 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_rwlock_t rwlock; int main(int argc, char **argv) { int rc=0; pthread_rwlockattr_t rwa; char readWriteLockName[16]; printf("Enter Testcase - %s\n", argv[0]); printf("Create a default read/write lock attribute\n"); rc = pthread_rwlockattr_init(&rwa); checkResults("pthread_rwlockattr_init\n", rc); printf("Create the read/write lock using a read/write lock attributes object\n"); rc = pthread_rwlock_init(&rwlock, &rwa); checkResults("pthread_rwlock_init\n", rc); memset(readWriteLockName, 0, sizeof(readWriteLockName)); strcpy(readWriteLockName,"READWRITE LOCK1"); printf("Set the name of the read/write lock\n"); rc = pthread_rwlock_setname_np(&rwlock, readWriteLockName); checkResults("pthread_rwlock_setname_np\n", rc); memset(readWriteLockName, 0, sizeof(readWriteLockName)); printf("Get the name of the read/write lock\n"); rc = pthread_rwlock_getname_np(&rwlock, readWriteLockName); checkResults("pthread_rwlock_getname_np\n", rc); printf("The read/write lock name is: %.15s\n", readWriteLockName); printf("Destroy the read/write lock\n"); pthread_rwlock_destroy(&rwlock); printf("Main completed\n"); return 0; }Example Output:
Enter Testcase - QP0WTEST/TPCRT0 Create a default read/write lock attribute Create the read/write lock using a read/write lock attributes object Set the name of the read/write lock Get the name of the read/write lock The read/write lock name is: READWRITE LOCK1 Destroy the read/write lock Main completed
[ Back to top | Pthread APIs | APIs by category ]