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