Are pthread attribute objects required to exist for the lifetime of the object that uses them, or is it safe to destroy them immediately after they've been used? For example:
// 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 );
Can the attributes now be safely destroyed with pthread_mutexattr_destroy(), or is it required to wait until after the mutex has been destroyed with pthread_mutex_destroy()?
Does the same apply for the other pthread objects that use attributes?
http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutexattr_init.html
After a mutex attributes object has been used to initialize one or more mutexes, any function affecting the attributes object (including destruction) shall not affect any previously initialized mutexes.
So it's perfectly safe to destroy the mutexattr object after you're done creating your mutexes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With