Boost logo

Boost :

Subject: Re: [boost] [threads] two threads gain lock on the same mutex??
From: Ryan Gallagher (ryan.gallagher_at_[hidden])
Date: 2010-01-02 17:00:28


David M. Cotter <me <at> davecotter.com> writes:

>
> i thought this was impossible. but i've caught it in the
> debugger *right now*!
>
> on thread 28, i've got this code:
>
> boost::mutex::scoped_lock lock(i_mutex);
[snip]
> PC --> if (!i_semID->timed_wait(lock, xt)) {

The timed_wait will not hold the lock for the duration of the wait.
It takes the lock so it can release it for the duration of the wait
and then re-acquire the lock upon the end of the wait before
returning. See how condition variables work as you're essentially
waiting on the condition of the time duration (xt):

http://tinyurl.com/ycn7rnl

HTH,

-Ryan


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