Hi evanb,
The absolute easiest way to do this will be to add a big lock + continuation to each request like
However, if your "use X" section takes a while (either because it's a big computation or it does some blocking thing), you could be tying up a lot of threads. In this case, there are several (more complex!) alternatives.
Finally, let me link you some good documentation around this: http://msdn.microsoft.com/en-us/library/dd492427.aspx#continuations.
Let us know if this works for you!
roschuma
The absolute easiest way to do this will be to add a big lock + continuation to each request like
// Important detail: Don't let BKL get destroyed before all the tasks finish
std::mutex BKL;
request_task.then([&BKL](pplx::task<foo> t) {
try {
auto x = t.get();
std::lock_guard<std::mutex> lock(BKL);
// Use X under the critical section
} catch (...) {
// Handle error
}
});
This removes the need for the vector of tasks, ensures that they're all waited on, and performs the (successful) continuations sequentially. If you need to do something after they're all done, you could stuff all of these continuations into a vector and use pplx::when_all(v.begin(), v.end()).then(...)
.However, if your "use X" section takes a while (either because it's a big computation or it does some blocking thing), you could be tying up a lot of threads. In this case, there are several (more complex!) alternatives.
Finally, let me link you some good documentation around this: http://msdn.microsoft.com/en-us/library/dd492427.aspx#continuations.
Let us know if this works for you!
roschuma