Boost logo

Boost Users :

Subject: Re: [Boost-users] [Thread] barrier destruction after wait() resultsin assertion
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-12-03 10:45:31


"Peter Dimov" <pdimov_at_[hidden]> writes:

> Anthony Williams:
> ...
>>> void f()
>>> {
>>> barrier->wait();
>>> }
>>>
>>> int main(void)
>>> {
>>> barrier.reset(new boost::barrier(2));
>>> boost::thread thread(boost::bind(&f));
>>> barrier->wait();
>>
>> At this point, there is no guarantee that f() has started.
>
> Yes there is.

Doh! Thanks Peter, apparently I'm not thinking straight today.

Anyway, there is no guarantee that the call to wait in f() has
*completed*, which means it might still own the mutex in barrier,
which means it is not safe to destroy the barrier at this point.

Anthony

-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

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