Remove precede and succede functions
Opened this issue · 0 comments
dian-lun-lin commented
In current Taro, we use precede and succeed to define task dependencies in a task graph. However, co_await already has the ability to manage dependencies (even finer-grained). I'm considering removing the precede and succeed and only using co_await (e.g., events) for task dependencies. Here shows a short example using events:
int main() {
size_t NUM_THREADS{2};
size_t NUM_EVENTS{4};
taro::Taro taro{NUM_THREADS};
auto events = taro.event_await(NUM_EVENTS); // create four events
for(size_t i = 0; i < NUM_EVENTS; ++i) {
taro.emplace([&, i]() {
std::cout << "setting event " << i << "\n";
events[i].set(); // set event i
});
taro.emplace([&, i]() -> taro::Coro {
co_await events[i]; // wait until event i is set
std::cout << "event " << i << " is set\n";
});
}
taro.schedule();
taro.wait();
}
Based on this example, we can also implement and and or relationships among tasks. For example,
taro.emplace([&]() -> taro::Coro {
co_await events[0] && events[1]; // wait until both events are set
// do something
co_await events[2] || events[3]; // wait until either one of events is set
}) ;
Using co_await other than precede/succeed is more flexible.