Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.4a |
both | POSIX(ON) |
#define _OPEN_THREADS
#define _OPEN_SYS
#include <pthread.h>
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
#define _UNIX03_THREADS
#define _OPEN_SYS
#include <pthread.h>
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
Destroys an initialized mutex attribute object. With a mutex attribute object, you can manage the characteristics of mutexes in your application. It defines the set of values to be used for the mutex during its creation. By establishing a mutex attribute object, you can create many mutexes with the same set of characteristics, without defining those characteristics for each mutex. pthread_mutexattr_init() is used to define a mutex attribute object.
If successful, pthread_mutexattr_destroy() returns 0.
Special behavior for Single UNIX Specification, Version 3: If unsuccessful, pthread_mutexattr_destroy() returns an error number to indicate the error.
⁄* CELEBP42 *⁄
#define _OPEN_THREADS
#define _OPEN_SYS ⁄* Needed to identify __MUTEX_RESCURSIVE *⁄
#include <pthread.h>
#include <stdio.h>
main() {
pthread_mutexattr_t attr;
pthread_mutex_t mutex;
if (pthread_mutexattr_init(&attr) != 0) {
perror("pthread_mutex_attr_init() error");
exit(1);
}
if (pthread_mutexattr_setkind_np(&attr, __MUTEX_RECURSIVE) != 0) {
perror("pthread_mutex_attr_setkind_np() error");
exit(2);
}
if (pthread_mutex_init(&mutex, &attr) != 0) {
perror("pthread_mutex_init() error");
exit(3);
}
if (pthread_mutexattr_destroy(&attr) != 0) {
perror("pthread_mutex_attr_destroy() error");
exit(4);
}
}