|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-07-05 15:33:51
Howard Hinnant wrote:
> On Jun 29, 2004, at 12:30 PM, Michael Glassford wrote:
>
>> Also, you could end up with some interesting situations like this:
[...]
Let's assume that the guarded entity is
int x;
>> void f(read_write_mutex m)
>> {
>> read_write_mutex::read_lock r(m);
int y = x;
>> if (...)
>> {
>> read_write_mutex::write_lock w(r); //lock promotion
assert( x == y); // always holds, we had a read+ lock all the
time
>> //...
>> }
>> //Point A
>> }
>
> How 'bout:
>
> void f(read_write_mutex& m)
> {
> read_write_mutex::read_lock r(m);
int y = x;
> if (...)
> {
> r.unlock();
Thread switch, write lock, write to x happens here.
> read_write_mutex::write_lock w(m);
> //... m is write locked
assert( x == y); // may fail
> w.transfer_to_read_lock(r);
> }
> //Point A ... m is read locked
> }
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk