pthread_rwlockattr_setpshared() — Set the process-shared read or write lock attribute

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX
Single UNIX Specification, Version 3
both
POSIX(ON)
OS/390® V2R7

Format

#define _OPEN_THREADS
#include <pthread.h>

int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared);
SUSV3:
#define _UNIX03_THREADS
#include <pthread.h>

int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared);

General description

The pthread_rwlockattr_setpshared() function sets the attribute pshared for the read or write lock attribute object attr.

A read or write lock attribute object allows you to manage the characteristics of read or write locks in your application. It defines the set of values to be used for a read or write lock during its creation. By establishing a read or write lock attribute object, you can create many read or write locks with the same set of characteristics, without needing to define those characteristics for each and every read or write lock. By using attr with the pthread_rwlockattr_setpshared() function you can define its process-shared value for a read or write lock.

The valid values for the attribute pshared are:
PTHREAD_PROCESS_SHARED
Permits a read or write lock to be operated upon by any thread that has access to the memory where the read or write lock is allocated, even if the read or write lock is allocated in memory that is shared by multiple processes.
PTHREAD_PROCESS_PRIVATE
A read or write lock can only be operated upon by threads created within the same process as the thread that initialized the read or write lock. When a new process is created by the parent process it will receive a different copy of the private read or write lock and this new read or write lock can only be used to serialize between threads in the child process. The default value of the attributed is PTHREAD_PROCESS_PRIVATE.

Returned value

If successful, pthread_rwlockattr_setpshared() returns 0.

If unsuccessful, pthread_rwlockattr_setpshared() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
The value specified for attr or pshared is not valid.

Special behavior for Single UNIX Specification, Version 3: If unsuccessful, pthread_rwlockattr_setpshared() returns an error number to indicate the error.

Related information