203 - 问,task get when_all when_any

203 - 问,task get when_all when_any

get

To get the result of the task, call the concurrency::task::getmethod. This method calls task::wait to wait for the task to finish, and therefore blocks execution of the current thread until the result is available.

&&

The tasks that you pass to when_all must be uniform. In other words, they must all return the same type.

You can also use the && syntax to produce a task that completes after a set of tasks complete, as shown in the following example.

C++

auto t = t1 && t2; // same as when_all

When_all result

The when_all function produces a task that completes after a set of tasks complete. This function returns astd::vector object that contains the result of each task in the set. 

||

As with when_all, the tasks that you pass to when_any must all return the same type.

You can also use the || syntax to produce a task that completes after the first task in a set of tasks completes, as shown in the following example.

C++

auto t = t1 || t2; // same as when_any

When_any result

The when_any function produces a task that completes when the first task in a set of tasks completes. This function returns a std::pair object that contains the result of the completed task and the index of that task in the set.

pair<TaskResult, size_t> result

参考资料

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dd492427.aspx

你可能感兴趣的:(203 - 问,task get when_all when_any)