Struct finish_wait¶
Defined in File finish_task.hpp
Struct Documentation¶
-
struct
concore::v1::finish_wait¶ Abstraction that allows waiting on multiple tasks to complete.
This is similar to finish_task, but instead of executing a task, this allows the user to wait on all the tasks to complete. This wait, as expected, is a busy-way: other tasks are executed while waiting for the finish event.
Similar to finish_task, this can also be used to implement concurrent joins. Instead of spawning a task whenever the tasks are complete, this allows the current thread to wait on the tasks to be executed
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 wait() method will be ‘unblocked’.
Example usage:
concore::finish_wait done(3); auto event = done_task.event(); // Spawn 3 tasks concore::spawn([event]{ do_work1(); event.notify_done(); }); concore::spawn([event]{ do_work2(); event.notify_done(); }); concore::spawn([event]{ do_work3(); event.notify_done(); }); // Wait for all 3 tasks to complete done.wait();
Public Functions
-
finish_wait(int count = 1)¶ Constructor.
-
finish_event
event() const¶ Getter for the finish_event object that should be distributed to other tasks.
-
void
wait()¶ Wait for all the tasks to complete.
This will wait for the right number of calls to the finish_event::notify_done() function on the exposed event. Until that, this will attempt to get some work from the system and execute it. Whenever the right number of tasks are completed (i.e., the right amount of calls to finish_event::notify_done() are made), then this will be unblocked; it will return as soon as possible.
This can be called several times, but after the first time this is unblocked, the subsequent calls will exit immediately.
-