title: Need help understanding how std::promise and std::future work in this case
body: <h1>Code</h1>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;atomic&gt;
  #include &lt;future&gt;
  
  void listenForInput(std::promise&lt;bool&gt;&amp;&amp; interruptPromise)
  {
      std::cin.get();
      std::atomic_thread_fence(std::memory_order_acquire);
      interruptPromise.set_value(true);
      std::cout &lt;&lt; &quot;[Speech 100] no u \n&quot;;
  }
  
  bool is_ready(std::future&lt;bool&gt; const&amp; f)
  { 
      return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready; 
  }
  
  int main() 
  {
      std::atomic_thread_fence(std::memory_order_acquire);
      std::promise&lt;bool&gt; interruptPromise;
      //interuptPromise.set_value(false); 
      /* Commenting line above makes program work. Uncommenting results in while
         loop below not being executed */
      std::atomic_thread_fence(std::memory_order_release);
      
      std::future&lt;bool&gt; interruptFuture = interuptPromise.get_future();
      
      std::thread reply(listenForInput, std::move(interruptPromise));
      
      while (!is_ready(interruptFuture))
      {
          std::cout &lt;&lt; &quot;Your mother was a hamster, &quot;
                       &quot;and your father smelt of elderberries &quot;
                       &quot;(Press any key to reply)\n&quot;;
          std::this_thread::sleep_for( std::chrono::seconds(2) );
      }
      
      reply.join();
      
      std::cin.get();
      
      return 0;
  }
  </code></pre>
  <h1>Context</h1>
  <p>In the code above in the main thread the same line of text is constantly being displayed until it's interrupted from the other thread. The interrupt occurs after any input from the user. The message of user making an input is being delivered to the main thread via <code>std::promise</code> and <code>std::future</code>. <code>is_ready</code> is an utilitarian function used for checking whether promise was satisfied.</p>
  <p>My interest lays in the third line of the <code>main()</code> function and what's around it. At first I tried to set value of <code>interruptPromise</code> in advance to false (which would indicate that interrupt didn't occur so that later in other thread I'd change it to true to indicate that it did occur). It resulted in <code>interruptPromise</code> being satisfied before <code>while</code> loop even started thus the loop not being executed.</p>
  <h1>Questions</h1>
  <ol>
  <li>I get that <code>std::promise</code> becomes satisfied when <code>set_value</code> is called. But how do I assign a value in advance and then make <code>std::future</code> react to it being changed (for instance <code>future</code> would react to <code>false</code> <code>bool</code> being changed to <code>true</code>)?</li>
  <li>Would I ever need to do such a thing?</li>
  <li>Does <code>std::promise</code> has default values for certain types (if it needs such at all)?</li>
  </ol>