May I destroy a mutexattr object before the mutex that was initialized with this mutexattr is used?

Viewed 324

Consider the following code:

pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);

pthread_mutex_t mut;
pthread_mutex_init(&mut, &attr);

pthread_mutexattr_destroy(&attr);

pthread_mutex_lock(&mut);

Is this code valid?

If the mutex is allowed to contain references to the attribute object it was initialized with, then I suppose I may not call pthread_mutexattr_destroy(&attr) before using the mutex.

1 Answers
Related