pthread_mutexattr_destroy()--Destroy Mutex Attributes Object


  Syntax:
 #include <pthread.h>
 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);   
  Service Program Name: QP0WPTHR

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_mutexattr_destroy() function destroys a mutex attributes object and allows the system to reclaim any resources associated with that mutex attributes object. This does not have an effect on any mutexes created using this mutex attributes object.


Authorities and Locks

None.


Parameters

attr
(Input) Address of the mutex attributes object to be destroyed

Return Value

0
pthread_mutexattr_destroy() was successful.

value
pthread_mutexattr_destroy() was not successful. value is set to indicate the error condition.

Error Conditions

If pthread_mutexattr_destroy() 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.

[EINVAL]

The value specified for the argument is not correct.


Related Information


Example

See Code disclaimer information for information pertaining to code examples.

#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;
}

Output:

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

API introduced: V4R3
Top | Pthread APIs | APIs by category