Boost logo

Boost Users :

From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-07-25 11:22:30


"Vladimir Pozdyaev" <vpozdyaev_at_[hidden]> writes:

> Hello.Is it feasible to make CVs&#39; destructors thread-safe?
> Consider the code below. It causes a failed assertion in
> basic_condition_variable::dispose_entry(...) when cv&#39;s
> destructor kicks in while notify_all() is still cleaning up. The
> problem is easily resolved by adding another mutex, but it would
> just look nicer if we could rely on cv&#39;s own features for
> that.Another alternative would be to make wait() return only after
> notify_xxx() has really finished its job. (Yes, I guess this code
> is not exactly a Good Practice :) , but it&#39;s not exactly
> logically inconsistent either. Or is it?)[Boost 1.35.0, MSVC2008,
> Win32 Debug configurationActually, it&#39;s not easy to make this
> particular code fail; adding a short sleep() in the beginning of
> dispose_entry(...) helps. This problem managed to appear quite
> systematically in a more complex program though.

First off, Boost 1.35.0 condition variables are broken on
Windows. Please update from subversion trunk or release branch.

However, it is never safe to destroy any object whilst another thread
might still be in a member function. If you use your mutex to protect
the notify too, everything will be fine.

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | 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