I want to run a series of C++11 threads (std::thread
) such that each thread can return a value to the process that created it.
I got some idea as to how to do this here.
However, when using std::future
, according to this, the execution is blocked until the value is ready. When I have multiple threads, I would like to use the return values of each thread as they become available, instead of accessing them in the order determined by the order in which the value from the future is obtained.
For example, if I have threads t1, t2, and t3, and I obtain their results as
t1.get();
t2.get();
t3.get();
then, I am potentially waiting till t1 has its result ready, even if t2 and t3 have completed their tasks.
Is there a way to overcome this?