Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-07-15 14:04:15


"Peter Dimov" <pdimov_at_[hidden]> writes:

> David Abrahams wrote:
>> Matt Hurd <matt.hurd_at_[hidden]> writes:
>>
>>> On Wed, 14 Jul 2004 15:27:08 -0400, David Abrahams
>>> <dave_at_[hidden]> wrote:
>>>> "Peter Dimov" <pdimov_at_[hidden]> writes:
>>>>
>>>> Can't you just check the hashes and only lock once in that case?
>>>
>>> AFAICT, you'd have to record the objects to which the specific thread
>>> had the lock otherwise you can't discriminate on who owns the lock.
>>
>> That's only true if a given thread can lock more than two objects at
>> the same time. Isn't that likely to lead to deadlock, regardless?
>
> Yep, have you read the last sentence in the block you quoted?

Yes, but I don't see how it's relevant.

> Anyway: consider this (oversimplified) situation:
>
> // f.cpp
>
> static object o;
>
> void f()
> {
> lock( &o );
> // do things
> unlock( &o );
> }
>
> // g.cpp
>
> void f();
>
> static object o2;
>
> void g()
> {
> lock( &o2 );
> f();
> unlock( &o2 );
> }
>
> Since the f() lock is always nested within the g() lock, there can be no
> deadlock.

Sorry, I don't see more than two objects locked at the same time here.

No big deal, I'm probably off base here so will relurk.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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