title: Boost Thread - How to acknowledge interrupt
body: <p>I have blocking task which will be performed by find_the_question() function. However, I do not want thread executing this function take more than 10 seconds. So in case it takes more than 10 seconds, I want to close that thread with cleaning all the resources.</p>
  
  <p>I tried to write a code for that, but somehow I am not able to get a interrupt in find_the_question() function if thread takes more than 10 seconds. Could you please tell me what am I doing wrong?</p>
  
  <pre><code>void find_the_question(std::string value)
  {
      //allocate x resources
      try{
          //do some process on resources
              sleep(14);
          //clean resources
      }
      catch(boost::thread_interrupted const&amp; )
      {
          //clean resources
          std::cout &lt;&lt; "Worker thread interrupted" &lt;&lt; std::endl;
      }
  }
  
  int main()
  {
          boost::posix_time::time_duration timeout = boost::posix_time::milliseconds(10000);
          std::cout &lt;&lt; "In main" &lt;&lt; std::endl;
          boost::thread t1(find_the_question, "Can you block me");
  
          t1.interrupt();
          if (t1.timed_join(timeout))
          {
            //finished
            std::cout &lt;&lt; "Worker thread finished" &lt;&lt; std::endl;
          }
          else
          {
            //Not finished;
            std::cout &lt;&lt; "Worker thread not finished" &lt;&lt; std::endl;
          }
  
          std::cout &lt;&lt; "In main end" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Output:
  If t1 takes more than 10 seconds to complete, I am getting following console output.</p>
  
  <pre><code>std::cout &lt;&lt; "In main" &lt;&lt; std::endl;
  std::cout &lt;&lt; "Worker thread not finished" &lt;&lt; std::endl;
  std::cout &lt;&lt; "In main end" &lt;&lt; std::endl;
  </code></pre>
  
  <p>whereas, I am expecting following output</p>
  
  <pre><code>std::cout &lt;&lt; "In main" &lt;&lt; std::endl;
  std::cout &lt;&lt; "Worker thread interrupted" &lt;&lt; std::endl;
  std::cout &lt;&lt; "Worker thread not finished" &lt;&lt; std::endl;
  std::cout &lt;&lt; "In main end" &lt;&lt; std::endl;
  </code></pre>
  
  <p>Could you please tell me what am I doing wrong. </p>
  
  <p>Thanks in advance</p>