title: std::future returned from std::async hangs while going out of scope
body: <p>I am using a combination of <code>std::async</code> and <code>std::future</code> from <code>C++ 11</code>. I am using to enforce a time_out on a certain activity that I do in my code which <strong>might</strong> take time as I try connecting to server. </p>
  
  <p>Following is how the code is:</p>
  
  <pre><code>#include &lt;future&gt;
  #include &lt;chrono&gt;
  
  std::size_t PotentiallyLongRunningActivity() {
      using namespace std::chrono_literals;
      std::this_thread::sleep_for(10000s);
      return 10;
  }
  
  bool DoActivity() {
  
    bool activity_done = false;
    auto my_future_result(std::async(std::launch::async, []() {
        return PotentiallyLongRunningActivity(); //returns size_t
    }));
  
    std::future_status my_future_status = my_future_result.wait_for(std::chrono::milliseconds(800));
    if (my_future_status == std::future_status::timeout) {
        activity_done = false;
    }
    else if (my_future_status == std::future_status::ready) {
        if (my_future_result.valid() &amp;&amp; my_future_result.get() &gt; 0) {
            activity_done = true;
        }
    }
  
    return activity_done;
    //my_future_result hangs while exiting this method !!!
  }
  
  int main(int argc, char *argv[])
  {
      DoActivity();
      return 0;
  }
  </code></pre>
  
  <p>Things work fine in most of the cases. The future times out &amp; is reported ready in many cases. But, Strange behavior I am observing is that in some cases the UI hangs because <code>my_future_result</code> when going out of scope hangs. I confirmed this by repeating the call to <code>my_future_result.get()</code> which never returns if called just before exiting the method. </p>
  
  <p>How can I get around this ? Is there some way I cancel or delete or terminate the <code>std::future</code> ?</p>