Boost logo

Boost :

Subject: [boost] [thread 1.48] Multiple interrupt/timed_join leads to deadlock
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2012-12-04 13:32:18

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.

This is the backtrace of it:

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

Is the code not valid or a real bug?

Gaetano Mendola

////////////////////// CODE //////////////////////
#include <iostream>
#include <boost/thread.hpp>

struct Runner {
   void operator()() {
     const boost::posix_time::time_duration mySeconds =

struct Interrupter {
   Interrupter(boost::thread& aThread, boost::barrier& aBarrier)
       : theThread(aThread),
   { }
   void operator()() {
     for (int i=0; i<1000;++i) {
   boost::thread& theThread;
   boost::posix_time::time_duration theSeconds;
   boost::barrier& theBarrier;

int main() {

    for (size_t i = 0; i < 1000000; ++i) {
     Runner myRunner;
     boost::thread myRunnerThread(myRunner);

     boost::barrier myBarrier(2);

     Interrupter myInterrupter1(myRunnerThread, myBarrier);
     Interrupter myInterrupter2(myRunnerThread, myBarrier);

     boost::thread myInterrupterThread1(myInterrupter1);
     boost::thread myInterrupterThread2(myInterrupter2);

     std::cout << "."; std::cout.flush();

Boost list run by bdawes at, gregod at, cpdaniel at, john at