TooManyCooks
TooManyCooks copied to clipboard
`tmc::spawn_group` - analogue to `tbb::task_group`
OneAPI/Intel TBB has a type called tbb::task_group which can be used to create and wait for a group of tasks imperatively.
tbb::task_group tg;
for (size_t i = 0; i < N; ++i) {
tg.run([=]() { do_something(); });
}
tg.wait();
This type would be useful to implement in TMC for two reasons:
- The current iterator-based approach provided by
tmc::spawn_many()is very efficient, but can introduce friction in some use cases. The imperative approach may be more straightforward, and it would be a nice tool to have available. - Simplifies the migration of TBB code to TMC by providing a similar interface.
The proposed API would have two constructors:
- a default constructor which would require specifying the awaitable type
- usage:
tmc::spawn_group<tmc::task<int>> tg();
- usage:
- a constructor taking the first instance of the awaitable group, which can deduce the awaitable type
- usage:
tmc::spawn_group tg(first);
- usage:
The group would be executed by co_await std::move(tg); or can be forked with .fork() which would produce a new awaitable type.