Dependency between iterations + semaphores
mzient opened this issue · comments
Hello,
I'm working on a system that runs a graph of operations (let's call them operators) but I can't implement all constraints that I need. The problems are visible even in a simple linear graph:
A -> B -> C
When I run it multiple times, the subsequent iterations of the graph can overlap, but the order of iterations of each operator must be maintained.
OK:
iter 0: A -> B -> C
iter 1: A -> B -> C
Invalid:
iter 0: A -> B....... -> C
iter 1: A -> B -> C // operator C got ahead of iter0
I've tried creating two taskflows with dependencies between specific tasks, but I get a hang.
tf::Executor exec(4);
tf::Taskflow tf1, tf2;
auto t1 = tf1.emplace([]() {
sync_print(std::cout, "Task 1 started\n");
std::this_thread::sleep_for(std::chrono::milliseconds(500));
sync_print(std::cout, "Task 1 finished\n");
});
auto t2 = tf2.emplace([]() {
sync_print(std::cout, "Task 2 started\n");
std::this_thread::sleep_for(std::chrono::milliseconds(500));
sync_print(std::cout, "Task 2 finished\n");
});
t2.succeed(t1);
auto f1 = exec.run(tf1);
auto f2 = exec.run(tf2); // so far, so good
// I get a properly sequenced output in the terminal
f1.get(); // <------------------- ...and then it hangs here
f2.get();
I thought of using AsyncTasks but that precludes the use of semaphores - and so far semaphores were the only way to implement waiting for an external condition that I could come up with (they do work across taskflows as long as they use a common executor).
Is there any way to achieve this kind of dependency and use semaphores?