Can I use a single "pthread_mutexattr_t" attribute to initialize two different mutexes?

c, mutex, pthreads, suse, x86-64

Solution

Yes, it is safe.

The `pthread_mutexattr_t` attribute is only used at mutex creation time, and is not modified by `pthread_mutex_init()`, nor is it needed after initialization (ie. you can also `pthread_mutexattr_destroy()` it later)

Problem

I am using two mutexes in my C program, I want both of them to be of type: `PTHREAD_MUTEX_ERRORCHECK` Other properties of both mutexes to be set as default. Can I use a single `pthread_mutexattr_t mutexAttrib;` with its "type" property set as above, to initialize both the mutexes? Is it safe?

Original source