title: std::future_error: No associated state
body: <p>I have a problem with C++ 11 future/promise.
  The following code works fine:</p>
  <pre><code>string s = &quot;not written&quot;;
  
  void write(promise&lt;void&gt;&amp;&amp; writePromise)
  {
      cout &lt;&lt; &quot;\nwrite()&quot; &lt;&lt; endl;
      this_thread::sleep_for(chrono::seconds(1));
      s = &quot;written&quot;;
      writePromise.set_value();
  }
  
  void read(future&lt;void&gt;&amp;&amp; readFut)
  {
      cout &lt;&lt; &quot;read(), waiting...&quot; &lt;&lt; flush;
      readFut.wait();
      cout &lt;&lt; &quot;\ns: '&quot; &lt;&lt; s &lt;&lt; &quot;'&quot; &lt;&lt; endl;
  }
  
  int main()
  {
      promise&lt;void&gt; writePromise;
      future&lt;void&gt; writeFuture = writePromise.get_future();
  
      thread tWrite(write, move(writePromise));
      thread tRead(read, move(writeFuture));
      
      tWrite.join();
      tRead.join();
  }
  </code></pre>
  <p>But once I change main() to this:</p>
  <pre><code>int main()
  {
      promise&lt;void&gt; writePromise;
  
      thread tWrite(write, move(writePromise));
      thread tRead(read, move(writePromise.get_future()));
      
      tWrite.join();
      tRead.join();
  }
  </code></pre>
  <p>I get the error:
  terminate called after throwing an instance of 'std::future_error'<br />
  what():  std::future_error: No associated state<br />
  Aborted (core dumped)</p>
  <p>This exception is supposed to be thrown if you call get_future() twice on the same promise.</p>
  <p>But all I did was just passing writePromise.get_future() to a function, so I don;t see how I call it twice.</p>
  <p>Can someone please help?</p>