Should pthread attributes exist throughout the life cycle of an object that uses them?

Should pthread attribute attributes exist for the lifetime of the object that uses them, or is it safe to destroy them immediately after using them? For instance:

// Create the mutex attributes. pthread_mutexattr_t attributes; pthread_mutexattr_init( &attributes ); pthread_mutexattr_settype( &attributes, PTHREAD_MUTEX_NORMAL ); // Create the mutex using the attributes from above. pthread_mutex_t mutex; pthread_mutex_init( &mutex, &attributes ); 

Is it now possible to safely destroy attributes using pthread_mutexattr_destroy (), or is it necessary to wait until the mutex is destroyed using pthread_mutex_destroy ()?

Does the same apply to other pthread objects that use attributes?

+4
source share
1 answer

http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutexattr_init.html

After the mutex attribute, the object is used to initialize one or more mutexes; any function affecting the attribute object (including destruction) should not affect previously initialized mutexes.

So it's completely safe to destroy the mutexattr object after you finish creating your mutexes.

+6
source

All Articles