std::future or std::shared_future to wait for multiple threads
<p>I have a thread that takes each element from a container and sends an upload request to the database. The upload is done synchronously.</p>

<p>The elements in the container are financial contracts and they may or may not have a data structure call ticktable associated to it. </p>

<p>Now, for those contracts which have a ticktable, I have to do a two pass upload.  1) first upload the ticktable to the db. db gives back an id.
2) attach the id to the contract and then upload the contract.</p>

<p>So for example, if I am looping over the container having 100 contracts, lets say 30 of them have ticktable and the rest 70 do not.</p>

<p>I am trying to figure out if <code>std::future</code> or a <code>std::shared_future</code> is suitable for such a task?</p>

<p>I tried to implement by having a future associated with each of the 30 contracts and call std::async with launch:async policy. So in the first pass of the loop, 3o threads are launched and the returning future is 'moved' to the container associated with the contract.
The other 70 contracts are just uploaded the usual way.</p>

<p>In the second pass, I hope to call <code>get()</code> on the stored future. If the request is complete, get the id and complete the contract upload with it. This probably is not going to work because I think moving the future to a container will detach the thread.</p>

<p>Please can you advise what sort of approach should I be taking to implement the behaviour that I want?</p>