5 May
2014
5 May
'14
7:39 p.m.
Niall Douglas wrote:
Consuming permits let you grant either with or without the mutex. Non-consuming permits will deadlock if you grant holding the mutex because of the guarantee of blocking until the release of all current waiters.
OK. Here you go then. * Initially P is 0 and p_mutex is unlocked. * Tc1, Tc2 lock p_mutex and call wait. * Tp1 locks p_mutex, sets P=1, unlocks p_mutex and gets suspended. * Tp2 locks p_mutex, sets P=1, unlocks p_mutex and calls notify_one. * Tc1 is unblocked with p_mutex locked, returns from wait, gets suspended. * Tp1 is resumed and calls notify_one. * Tc2 is unblocked and blocks on p_mutex, which is held by Tc1. * Tc1 is resumed, sees P=1, sets P=0, unlocks p_mutex. * Tc2 is unblocked, sees P=0.