[Bordeaux-threads-devel] Dead lock in condition wait.

Paul Khuong pvk at pvk.ca
Fri Mar 30 17:32:38 UTC 2012


In article 
<CALOceq_ccA9118qZPpSQ763yaOnFecQLkzS1eEj_cZ271K1xiw at mail.gmail.com>,
 rayfill <rayfill at gmail.com> wrote:

> I use condition-wait in many acquire recursive-lock. Other thread try
> to acquire recusirve-lock's lock at dead locked.

Don't.

"Never use a recursive mutex with condition variables because the 
implicit unlock performed by pthread_cond_wait() or 
pthread_cond_timedwait() will not actually release the mutex if it had 
been locked multiple times." 
(see 
http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#t
ag_22_02_09_08)

Partially releasing the recursive mutex on condition-wait will almost 
always result in a deadlock. However, fully releasing it may very well 
break invariants in sections of code that acquired the mutex, earlier in 
the call stack.

Paul Khuong





More information about the bordeaux-threads-devel mailing list