Boost logo

Threads-Devel :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-04-14 18:38:18


---------------------------
Vicente Juan Botet Escriba
----- Original Message -----
From: "Frank Mori Hess" <frank.hess_at_[hidden]>
To: "Discussions about the boost.thread library"
<threads-devel_at_[hidden]>
Sent: Monday, April 14, 2008 7:42 PM
Subject: Re: [Threads-devel] shared mutex locking discipline

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Monday 14 April 2008 11:02 am, vicente.botet wrote:
>> > mutex_type m;
>> > shared_lock<mutex_type> shared(m);
>> > upgrade_lock<mutex_type> upgrade(m); (*)
>> > shared.unlock();
>>
>> Your code deadlocks on (*). the upgrade_lock(Mutex&) constructor lock the
>> mutex that is already shared.
>
> No, an upgrade_lock shares ownership with shared_locks. It would only
> deadlock against a unique_lock or another upgrade_lock.

I'm sorry. I haven't see that the call to lock was upgrade_lock::lock()
    lock(); // <<<<<<<<<<<<<<<
and not on the mutex
    m_.lock();

>
>> See the code
>>
>> <code>
>> explicit upgrade_lock(Mutex& m_):
>> m(&m_),is_locked(false)
>> {
>> lock(); // <<<<<<<<<<<<<<<
>
> If you look at the implementation of upgrade_lock::lock(), it calls
> lock_upgrade() on the mutex, not the unique lock().

Thanks Frank

>> }
>> upgrade_lock(Mutex& m_,bool do_lock):
>> m(&m_),is_locked(false)
>> {
>> if(do_lock)
>> {
>> lock();
>> }
>> }
>> <code/>
>>
>
> - --
> Frank
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFIA5ds5vihyNWuA4URAhbvAJ4ndO+ar67cImecb2XI4tVGnRc38QCcCPi1
> uEduRFIIAHADCFFW1ltkFW0=
> =dWNW
> -----END PGP SIGNATURE-----
> _______________________________________________
> threads-devel mailing list
> threads-devel_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/threads-devel
>


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk