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

StackOverflow https://stackoverflow.com/questions/18333238

Вопрос

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