Boost logo

Threads-Devel :

From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-04-14 13:42:03


-----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.

> 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().

> }
> 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 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