|
Boost Users : |
From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2007-05-09 04:06:03
Kirit Sælensminde <kirit.saelensminde_at_[hidden]> writes:
[snip]
> // Notify joins
> boost::mutex::scoped_lock lock( m_mutex );
> j->first->m_completed = true;
> j->first->m_control.notify_all();
[snip]
> Nullable< wstring > FSLib::Worker::Join< void >::exception() {
> boost::mutex::scoped_lock lock( m_mutex );
> m_control.wait( lock, boost::lambda::bind( &Join< void >::m_completed,
> this ) );
> return m_exception;
> }
You're locking different mutexes. In the notify case, you're locking the
worker thread mutex, but in the wait case you're locking the Join
mutex. Whilst this is legal for the condition variable (you don't need the
mutex locked to call notify_all()), it means that m_completed isn't
necessarily visible to the waiting thread when the notify wakes it up. Since
the notify is only called once, if m_completed wasn't set when it woke, then
it will never wake again.
Yes, the MSVC documentation says that volatile writes are immediate, but that
doesn't mean that they become immediately visible to another thread,
particularly on a multicore or multi-CPU system.
Anthony
-- Anthony Williams Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net