pthread_attr_destroy() — Destroy the thread attributes object

Standards

Standards / Extensions C or C++ Dependencies

POSIX.4a
Single UNIX Specification, Version 3

both

POSIX(ON)

Format

#define _OPEN_THREADS
#include <pthread.h>

int pthread_attr_destroy(pthread_attr_t *attr);
SUSV3:
#define _UNIX03_THREADS
#include <pthread.h>

int pthread_attr_destroy(pthread_attr_t *attr);

General description

Removes the definition of the thread attributes object. An error results if a thread attributes object is used after it has been destroyed.

attr is a pointer to a thread attribute object initialized by pthread_attr_init().

You can use a thread attribute object to manage the characteristics of threads in your application. It defines the set of values to be used for the thread during its creation. By establishing a thread attribute object, you can create many threads with the same set of characteristics, without defining those characteristics for each thread. You can define more than one thread attribute object.

If a thread attribute object is shared between threads, the application must provide the necessary synchronization because a thread attribute object is defined in the application's storage.

Returned value

If successful, pthread_attr_destroy() returns 0.

If unsuccessful, pthread_attr_destroy() returns -1.

There are no documented errno values. Use perror() or strerror() to determine the cause of the error.

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

Example

CELEBP06
⁄* CELEBP06 *⁄                                   
#define _OPEN_THREADS                                                           
#include <stdio.h>                                                              
#include <pthread.h>                                                            
                                                                                
void *thread1(void *arg) {                                                      
  pthread_exit(NULL);                                                           
}                                                                               
                                                                                
int main()                                                                      
{                                                                               
   pthread_t      thid;                                                         
   pthread_attr_t attr;                                                         
                                                                                
   if (pthread_attr_init(&attr) == -1) {                                        
      perror("error in pthread_attr_init");                                     
      exit(1);                                                                  
   }                                                                            
                                                                                
   if (pthread_create(&thid, &attr, thread1, NULL) == -1) {                     
      perror("error in pthread_create");                                        
      exit(2);                                                                  
   }                                                                            
                                                                                
   if (pthread_detach(&thid) == -1) {                                           
      perror("error in pthread_detach");                                        
      exit(4);                                                                  
   }                                                                            
                                                                                
   if (pthread_attr_destroy(&attr) == -1) {                                     
      perror("error in pthread_attr_destroy");                                  
      exit(5);                                                                  
   }                                                                            
   exit(0);                                                                     
}                                                                               

Related information