Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-07-05 16:24:44


boost is back up, yea! :-)

On Jul 5, 2004, at 4:33 PM, Peter Dimov wrote:

> 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

I'm not following that x==y always holds. If two threads concurrently
hold a read lock, and concurrently try to obtain a write lock, only one
thread will get the write lock, the other will block. Assuming the one
thread that got the write lock changes x, then the thread that blocked
will fire its assert when it finally unblocks and gets the write lock.

What am I missing?

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk