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?

有帮助吗?

解决方案

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)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top