X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cef59d338bade8ea4224fbe3eebb9ffe5bf08c4d..e98ff738e16a6e5a18426c8686407511f4c0c8a4:/examples/cpp/task-switch-host/s4u-task-switch-host.cpp diff --git a/examples/cpp/task-switch-host/s4u-task-switch-host.cpp b/examples/cpp/task-switch-host/s4u-task-switch-host.cpp index 2a22323f45..6f8c62b849 100644 --- a/examples/cpp/task-switch-host/s4u-task-switch-host.cpp +++ b/examples/cpp/task-switch-host/s4u-task-switch-host.cpp @@ -46,29 +46,35 @@ int main(int argc, char* argv[]) exec2->add_successor(comm2); // Add a function to be called when tasks end for log purpose - sg4::Task::on_completion_cb([](const sg4::Task* t) { - XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); - }); + sg4::Task::on_completion_cb( + [](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); }); - // Add a function to be called before each executions of comm0 + // Add a function to be called before each firing of comm0 // This function modifies the graph of tasks by adding or removing // successors to comm0 - comm0->on_this_start_cb([comm0, exec1, exec2, jupiter, fafard](sg4::Task*) { + comm0->on_this_start_cb([&comm0, exec1, exec2, jupiter, fafard](const sg4::Task*) { static int count = 0; - if (count % 2 == 0) { + if (count % 2 == 0) comm0->set_destination(jupiter); + else + comm0->set_destination(fafard); + count++; + }); + + comm0->on_this_completion_cb([&comm0, exec1, exec2, jupiter, fafard](const sg4::Task*) { + static int count = 0; + if (count % 2 == 0) { comm0->add_successor(exec1); comm0->remove_successor(exec2); } else { - comm0->set_destination(fafard); comm0->add_successor(exec2); comm0->remove_successor(exec1); } count++; }); - // Enqueue four executions for task comm0 - comm0->enqueue_execs(4); + // Enqueue four firings for task comm0 + comm0->enqueue_firings(4); // Start the simulation e.run();