#include <pthread.h> int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared);Service Program Name: QP0WPTHR
The pthread_mutexattr_getpshared() function retrieves the current setting of the process shared attribute from the mutex attributes object. The process shared attribute indicates whether the mutex that is created using the mutex attributes object can be shared between threads in separate processes (PTHREAD_PROCESS_SHARED) or shared between threads within the same process (PTHREAD_PROCESS_PRIVATE).
Even if the mutex in storage is accessible from two separate processes, it cannot be used from both processes unless the process shared attribute is PTHREAD_PROCESS_SHARED.
The default pshared attribute for mutex attributes objects is PTHREAD_PROCESS_PRIVATE.
None.
If pthread_mutexattr_getpshared() 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.
The value specified for the argument is not correct.
See Code disclaimer information for information pertaining to code examples.
#include <pthread.h> #include <stdio.h> #include "check.h" void showPshared(int pshared) { printf("The pshared attribute is: "); switch (pshared) { case PTHREAD_PROCESS_PRIVATE: printf("PTHREAD_PROCESS_PRIVATE\n"); break; case PTHREAD_PROCESS_SHARED: printf("PTHREAD_PROCESS_SHARED\n"); break; default : printf("! pshared Error !\n"); exit(1); } return; } int main(int argc, char **argv) { int rc=0; pthread_mutexattr_t mta; int pshared=0; printf("Entering testcase\n"); printf("Create a default mutex attribute\n"); rc = pthread_mutexattr_init(&mta); checkResults("pthread_mutexattr_init()\n", rc); printf("Check pshared attribute\n"); rc = pthread_mutexattr_getpshared(&mta, &pshared); checkResults("pthread_mutexattr_getpshared()\n", rc); showPshared(pshared); printf("Destroy mutex attribute\n"); rc = pthread_mutexattr_destroy(&mta); checkResults("pthread_mutexattr_destroy()\n", rc); printf("Main completed\n"); return 0; }
Output:
Entering testcase Create a default mutex attribute Check pshared attribute The pshared attribute is: PTHREAD_PROCESS_PRIVATE Destroy mutex attribute Main completed
Top | Pthread APIs | APIs by category |