I have used std::async
for speeding up the execution of a task, which was previously being executed sequentially.
My implementation does the following:
- Launches a pre-configured number of tasks (for e.g. at max 10 concurrent tasks)
- The futures for these tasks are stored in a vector.
- As soon as one task is finished, it launches another task, so that at any point of time, at max 10 tasks (this value is configured) are running.
- After launching 10 tasks, my implementation waits for the oldest task (i.e. the first task in the vector) to complete, by calling get() on that future.
Though this works fine, it is possible that any of the 10 tasks could complete first. My implementation always waits on the first task in the vector. Is there a way to know, which of the 10 tasks completed first?
For e.g. future object itself signalling that it is ready.
I want to achieve functionality similar to "WhenAny()" function mentioned in this article: https://msdn.microsoft.com/en-us/library/jj155756.aspx