Skip to content

Task_Groups

Olaf Maibaum edited this page Oct 9, 2020 · 1 revision

Task Groups

When a task should become activated again only after also some other task has been executed, these tasks can be joined into a group. The group mechanism changes the time when the reset operation is triggered. For tasks inside the group a reset is only performed when all tasks in the group have been executed. If at least one task has not been executed, the state of all its inputs remains in the state activated and pushes on the connected channel have no effect until the reset operation is performed.

Taking the minimal program and extending it to two tasks and channels.

#include <unistd.h>

#include <schedulerProvider.h>
#include <taskGroup.h>

#include "SingleDataChannel.hpp"
#include "SingleDataPrinterTask.hpp"

Tasking::SchedulerProvider<1u, Tasking::SchedulePolicyFifo> scheduler;
SingleDataChannel<std::string> channel1;
SingleDataChannel<std::string> channel2;
SingleDataPrinterTask task1(scheduler);
SingleDataPrinterTask task2(scheduler);
Tasking::GroupProvider<2> group;

int main(int argc, char** argv)
{
    task1.configureInput(0u, channel1);
    task2.configureInput(0u, channel2);
    group.join(task1);
    group.join(task2);

    scheduler.start();

    channel1.push("First push on channel 1");
    sleep(1);
    channel1.push("Second push on channel 1");
    sleep(1);
    channel2.push("First push on channel 2");
    sleep(1);
    channel2.push("Second push on channel 2");

    scheduler.terminate(true);

    return 0;
}

The output will be:

First push on channel 1
First push on channel 2
Second push on channel 1
Second push on channel 2

The second push to channel1 cannot activate the task until task2 is executed. After execution of task2, the reset operation on both tasks is processed and with the reset of task1 the second push leads to an immediate activation of task1.

The sleeps in the example are for the concurrent processing of main function and processing of tasks by the executor thread in the scheduler. If not used, you have a good chance of seeing only the second pushes due to the use of a single buffer. A queue is the recommended data specialization in the example. One queue will be the FIFO buffer in the folder channel.

Clone this wiki locally