pthread_rwlock_getname_np()--Get Name of Read/Write Lock
Syntax
#include <pthread.h> int pthread_rwlock_getname_np(pthread_rwlock_t *rwlock, char *name);Service Program Name: QP0WPTHR
Default Public Authority: *USE
Threadsafe: Yes
Signal Safe: Yes
The pthread_rwlock_getname_np() function retrieves the name of with the read/write lock specified by rwlock. The buffer specified by name must be at least 16 characters in length. The returned read/write lock name will be null terminated in the output buffer.
By default, each pthread_rwlock_t does not have a name associated with it.
Note: This function is not portable.
Parameters
- rwlock
- (Input) The address of the read/write lock object
- name
- (Output) Address of 16 byte buffer to receive the name
Authorities and Locks
None.
Return Value
- 0
- pthread_rwlock_getname_np() was successful.
- value
- pthread_rwlock_getname_np() was not successful. value is set to indicate the error condition.
Error Conditions
If pthread_rwlock_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] |
Usage Notes
- No CCSID conversion is performed when storing or displaying the name.
Related Information
- The <pthread.h> header file. See Header files for Pthread functions.
- pthread_rwlock_setname_np()--Set Name in Read/Write Lock
- pthread_rwlock_init()--Initialize Read/Write Lock
- pthread_rwlock_destroy()--Destroy Read/Write Lock
Example
The following example will get 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
API introduced: IBM® i 7.1
[ Back to top | Pthread APIs | APIs by category ]