pthread_mutexattr_setpshared() — Set the process-shared mutex 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_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
SUSV3:
#define _UNIX03_THREADS
#include <pthread.h>

int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);

General description

The pthread_mutexattr_setpshared() function sets the attribute pshared for the mutex attribute object attr.

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

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

Returned value

If successful, pthread_mutexattr_setpshared() returns 0.

If unsuccessful, pthread_mutexattr_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_mutexattr_setpshared() returns an error number to indicate the error.

Related information