Boost logo

Boost :

Subject: Re: [boost] [threads] two threads gain lock on the same mutex??
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-01-02 16:55:30


AMDG

David M. Cotter wrote:
> 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);
>
> i_waitingB = true;
>
> if (i_semID) {
>
> if (!i_signaledB) {
> boost::xtime xt;
>
> if (wait_duration == kDurationForever) {
> xt = boost::xdelay(kEventDurationDay);
> } else {
> xt = boost::xdelay(0, 0, kNanoPerMicro * wait_duration); // wait_duration is in microseconds
> }
>
> PC --> if (!i_semID->timed_wait(lock, xt)) {
> err = kMPTimeoutErr;
> }
> }
>
> if (!err) {
> i_signaledB = false;
> }
> } else {
> err = kMPDeletedErr;
> }
>
> the PC is waiting (for 24 hours) in the timed_wait() call (wait_duration = kDurationForever)
>
> that thread it just hanging, which is correct.
>
> however on thread 30 i've got this:
>
> if (!err) {
> boost::mutex::scoped_lock lock(i_mutex);
>
> PC --> i_signaledB = true; < breakpoint set here, now hit
> CF_ASSERT(i_semID);
> IX(i_semID->notify_one());
> }
>
> that should be impossible, right? the PC should in fact block on that scoped_lock, right??
> yes: the mutex IS the same mutex on both threads
> the i_mutex is of type:
> boost::mutex i_mutex;
>
> it is not a shared mutex
>
> i realize that if the scoped_lock were actually functioning as expected, that the signal could never be sent to the semaphore to wake up. i'll fix the code design after i figure out WHY the lock is not actually locking.
> but the thread WAS waking up, my program is actually functioning as it should, but given the above code it should NOT be working.
>
> what's going on here?

timed_wait releases the lock.

In Christ,
Steven Watanabe


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