
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?

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

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
participants (3)
-
David M. Cotter
-
Ryan Gallagher
-
Steven Watanabe