jeudi 6 mai 2021

In POSIX, why can't a single condvar be used with multiple mutexes?

Why is the behavior undefined when a POSIX condition variable is used with multiple mutexes?

Excerpt from the 2018 edition:

When a thread waits on a condition variable, having specified a particular mutex to either the pthread_cond_timedwait() or the pthread_cond_wait() operation, a dynamic binding is formed between that mutex and condition variable that remains in effect as long as at least one thread is blocked on the condition variable. During this time, the effect of an attempt by any thread to wait on that condition variable using a different mutex is undefined

I suppose it's because of some kind of implementation detail of some specific system, so can someone confirm or refute it?

C11 (and C17) condition variables don't seem to have such limitation, and why?

Aucun commentaire:

Enregistrer un commentaire