pthread_mutexattr_getpshared - Man Page

get/set process-shared mutex attribute

Library

POSIX threads library (libpthread, -lpthread)

Synopsis

#include <pthread.h>

int pthread_mutexattr_getpshared(
                      const pthread_mutexattr_t *restrict attr,
                      int *restrict pshared);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
                      int pshared);

Description

These functions get and set the process-shared attribute in a mutex attributes object. This attribute must be appropriately set to ensure correct, efficient operation of a mutex created using this attributes object.

The process-shared attribute can have one of the following values:

PTHREAD_PROCESS_PRIVATE

Mutexes created with this attributes object are to be shared only among threads in the same process that initialized the mutex. This is the default value for the process-shared mutex attribute.

PTHREAD_PROCESS_SHARED

Mutexes created with this attributes object can be shared between any threads that have access to the memory containing the object, including threads in different processes.

pthread_mutexattr_getpshared() places the value of the process-shared attribute of the mutex attributes object referred to by attr in the location pointed to by pshared.

pthread_mutexattr_setpshared() sets the value of the process-shared attribute of the mutex attributes object referred to by attr to the value specified in pshared.

If attr does not refer to an initialized mutex attributes object, the behavior is undefined.

Return Value

On success, these functions return 0. On error, they return a positive error number.

Errors

pthread_mutexattr_setpshared() can fail with the following errors:

EINVAL

The value specified in pshared is invalid.

ENOTSUP

pshared is PTHREAD_PROCESS_SHARED but the implementation does not support process-shared mutexes.

Standards

POSIX.1-2008.

History

POSIX.1-2001.

See Also

pthread_mutexattr_init(3), pthreads(7)

Referenced By

pthread_mutexattr_init(3).

The man page pthread_mutexattr_setpshared(3) is an alias of pthread_mutexattr_getpshared(3).

2024-05-02 Linux man-pages 6.9.1