1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u.hpp"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
10 simgrid::s4u::ExecPtr child;
14 double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
16 simgrid::s4u::ExecPtr first_parent = simgrid::s4u::this_actor::exec_init(computation_amount);
17 simgrid::s4u::ExecPtr second_parent = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
19 child = simgrid::s4u::this_actor::exec_init(computation_amount);
21 first_parent->add_successor(child.get());
22 second_parent->add_successor(child.get());
23 second_parent->start();
25 second_parent->wait();
28 static void vetoed_worker()
30 child->vetoable_start();
31 while (not child->test()) {
32 if (child->get_state() == simgrid::s4u::Exec::State::STARTING)
33 XBT_INFO("child cannot start yet");
35 XBT_INFO("child is now in state %d", (int)child->get_state());
36 simgrid::s4u::this_actor::sleep_for(0.25);
38 XBT_INFO("Should be okay now, child is in state %d", (int)child->get_state());
41 int main(int argc, char* argv[])
43 simgrid::s4u::Engine e(&argc, argv);
44 e.load_platform(argv[1]);
46 simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Fafard"), worker);
47 simgrid::s4u::Actor::create("vetoed_worker", simgrid::s4u::Host::by_name("Fafard"), vetoed_worker);
51 XBT_INFO("Simulation time %g", e.get_clock());