Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency between iterations + semaphores #570

Open
mzient opened this issue Apr 8, 2024 · 0 comments
Open

Dependency between iterations + semaphores #570

mzient opened this issue Apr 8, 2024 · 0 comments

Comments

@mzient
Copy link

mzient commented Apr 8, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant