paduraru2009
paduraru2009

Reputation: 615

How to wait for a single task in Intel TBB in a task group and kill others?

In Intel TBB, I'm trying to: 1. Create a set of tasks 2. Let them run 3. When one of them finishes, I get some result out of it and kill the others.

How can I do that ? I can see only API to wait for all not just single...

Thanks.

Upvotes: 0

Views: 1565

Answers (1)

Arch D. Robison
Arch D. Robison

Reputation: 4049

The task that finishes can store its result in a known place and cancel the group with task::self().cancel_group_execution(). The wait_for_all() will then become unblocked and that thread can load the result from the known place.
https://www.threadingbuildingblocks.org/docs/help/tbb_userguide/Cancellation_Without_An_Exception.html shows how to use cancel_group_execution().

Upvotes: 5

Related Questions