pthread_mutexattr_destroy() — Destroy a mutex attribute object

Standards

Standards / Extensions C or C++ Dependencies

POSIX.4a
Single UNIX Specification, Version 3

both

POSIX(ON)

Format

#define _OPEN_THREADS
#define _OPEN_SYS
#include <pthread.h>

int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
SUSV3:
#define _UNIX03_THREADS
#define _OPEN_SYS
#include <pthread.h>

int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);

General description

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.

Returned value

If successful, pthread_mutexattr_destroy() returns 0.

If unsuccessful, pthread_mutexattr_destroy() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
The value specified for attr is not valid.

Special behavior for Single UNIX Specification, Version 3: If unsuccessful, pthread_mutexattr_destroy() returns an error number to indicate the error.

Example

CELEBP42
⁄* 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);
  }
}

Related information