|
Boost : |
Subject: Re: [boost] [thread] Request review of new synchronisation object, boost::permit<>
From: Peter Dimov (lists_at_[hidden])
Date: 2014-05-05 15:39:12
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk