#include <pthread.h> int pthread_mutexattr_init(pthread_mutexattr_t *attr);Service Program Name: QP0WPTHR
The pthread_mutexattr_init() function initializes the mutex attributes object referenced by attr to the default attributes. The mutex attributes object can be used in a call to pthread_mutex_init() to create a mutex.
None.
If pthread_mutexattr_init() 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.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#include <pthread.h> #include <stdio.h> #include "check.h" pthread_mutex_t mutex; int main(int argc, char **argv) { int rc=0; pthread_mutexattr_t mta; printf("Entering testcase\n"); printf("Create a default mutex attribute\n"); rc = pthread_mutexattr_init(&mta); checkResults("pthread_mutexattr_init\n", rc); printf("Create the mutex using a mutex attributes object\n"); rc = pthread_mutex_init(&mutex, &mta); checkResults("pthread_mutex_init(mta)\n", rc); printf("- At this point, the mutex with its default attributes\n"); printf("- Can be used from any threads that want to use it\n"); printf("Destroy mutex attribute\n"); rc = pthread_mutexattr_destroy(&mta); checkResults("pthread_mutexattr_destroy()\n", rc); printf("Destroy mutex\n"); rc = pthread_mutex_destroy(&mutex); checkResults("pthread_mutex_destroy()\n", rc); printf("Main completed\n"); return 0; }
Entering testcase Create a default mutex attribute Create the mutex using a mutex attributes object - At this point, the mutex with its default attributes - Can be used from any threads that want to use it Destroy mutex attribute Destroy mutex Main completed
[ Back to top | Pthread APIs | APIs by category ]