title: std::promise and std::future in c++
body: <blockquote>
    <p>std::promise provides a means of setting a value (of type T), which
    can later be read through an associated std::future object</p>
  </blockquote>
  
  <ol>
  <li><p>How exactly these two are associated? </p></li>
  <li><p>Is my concern reasonable that the future would pair with the wrong promise?</p></li>
  </ol>
  
  <p>update: example from concurrency in action... (the code cannot compile, though)</p>
  
  <pre><code>#include &lt;future&gt;
  void process_connections(connection_set&amp; connections)
  {
      while(!done(connections)){
          for(connection_iterator
          connection=connections.begin(),end=connections.end();
          connection!=end;
          ++connection)
          {
              if(connection-&gt;has_incoming_data()){
                  data_packet data=connection-&gt;incoming();
                  std::promise&lt;payload_type&gt;&amp; p=
                  connection-&gt;get_promise(data.id);
                  p.set_value(data.payload);
              }
              if(connection-&gt;has_outgoing_data()){
                  outgoing_packet data=
                  connection-&gt;top_of_outgoing_queue();
                  connection-&gt;send(data.payload);
                  data.promise.set_value(true);
              }
          }
      }
  }
  </code></pre>