Struct finish_task

Struct Documentation

struct concore::v1::finish_task

Abstraction that allows executing a task whenever multiple other tasks complete.

This is created with a task (and an executor) and a count number. If the specific number of other tasks will complete, then the given task is executed (in the given executor).

With the help of this class one might implement a concurrent join: when a specific number of task are done, then a continuation is triggered.

This abstraction can also be used to implement simple continuation; it’s just like a join, but with only one task to wait on.

This will expose a finish_event object with the event() function. Other tasks will call finish_event::notify_done() whenever they are completed. When the right amount of tasks call it, then the task given at the constructor will be executed.

After constructing a finish_task object, and passing the corresponding finish_event to the right amount of other tasks, this object can be safely destructed. Its presence will not affect in any way the execution of the task.

Example usage:

concore::finish_task done_task([]{
    printf("done.");
    system_cleanup();
}, 3);
// Spawn 3 tasks
auto event = done_task.event();
concore::spawn([event]{
    do_work1();
    event.notify_done();
});
concore::spawn([event]{
    do_work2();
    event.notify_done();
});
concore::spawn([event]{
    do_work3();
    event.notify_done();
});
// When they complete, the first task is triggered

See

finish_event, finish_wait

Public Functions

finish_task(task &&t, any_executor e, int count = 1)

Constructor with a task and executor.

finish_task(task &&t, int count = 1)

Constructor with a task.

template<typename F>
finish_task(F f, any_executor e, int count = 1)

Constructor with a functor and executor.

template<typename F>
finish_task(F f, int count = 1)

Constructor with a functor.

finish_event event() const

Getter for the finish_event object that should be distributed to other tasks.