Boost logo

Boost :

Subject: Re: [boost] [thread 1.48] Multiple interrupt/timed_join leads to deadlock
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2012-12-05 03:16:45


On 04/12/12 18:32, Gaetano Mendola wrote:
> Hi all,
> I was investigating a rare deadlock when issuing an interrupt and
> a timed_join in parallel. I come out with the the following code
> showing the behavior.
>
> The deadlock is rare so sometime you need to wait a bit.
>
> I couldn't try it with boost 1.52 because the code is invalid
> due the precondition of "thread joinable" when issuing the
> timed_join.

That's a hint.

> Is the code not valid or a real bug?

The code is invalid: you keep trying to interrupt and join even after
the thread has been joined! Once the thread has been joined, the thread
handle is no longer valid, and you should exit the loop.

> void operator()() {
> theBarrier.wait();
> for (int i=0; i<1000;++i) {
> theThread.interrupt();
> theThread.timed_join(theSeconds);
> }
> }

Anthony

-- 
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++11 thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

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