Question

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?

Was it helpful?

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top