XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
-simgrid::s4u::ExecPtr second;
+simgrid::s4u::ExecPtr child;
static void worker()
{
double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
- simgrid::s4u::ExecPtr first = simgrid::s4u::this_actor::exec_init(computation_amount);
- second = simgrid::s4u::this_actor::exec_init(computation_amount);
+ simgrid::s4u::ExecPtr first_parent = simgrid::s4u::this_actor::exec_init(computation_amount);
+ simgrid::s4u::ExecPtr second_parent = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
- first->add_successor(second.get());
- first->start();
- first->wait();
+ child = simgrid::s4u::this_actor::exec_init(computation_amount);
+
+ first_parent->add_successor(child.get());
+ second_parent->add_successor(child.get());
+ second_parent->start();
+ first_parent->wait();
+ second_parent->wait();
}
static void vetoed_worker()
{
- second->vetoable_start();
- XBT_INFO("%d %d", (int)second->get_state(), second->has_dependencies());
- second->wait();
+ child->vetoable_start();
+ while (not child->test()) {
+ if (child->get_state() == simgrid::s4u::Exec::State::STARTING)
+ XBT_INFO("child cannot start yet");
+ else
+ XBT_INFO("child is now in state %d", (int)child->get_state());
+ simgrid::s4u::this_actor::sleep_for(0.25);
+ }
+ XBT_INFO("Should be okay now, child is in state %d", (int)child->get_state());
}
int main(int argc, char* argv[])
#!/usr/bin/env tesh
$ ${bindir:=.}/s4u-exec-dependent ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 0.250000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 0.500000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 0.750000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 1.000000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 1.250000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 1.500000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 1.750000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 2.000000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 2.250000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 2.500000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 2.750000] (2:vetoed_worker@Fafard) child cannot start yet
+> [ 3.000000] (2:vetoed_worker@Fafard) child is now in state 2
+> [ 3.250000] (2:vetoed_worker@Fafard) child is now in state 2
+> [ 3.500000] (2:vetoed_worker@Fafard) child is now in state 2
+> [ 3.750000] (2:vetoed_worker@Fafard) child is now in state 2
+> [ 4.000000] (2:vetoed_worker@Fafard) Should be okay now, child is in state 5
+> [ 4.000000] (0:maestro@) Simulation time 4
*/
virtual Activity* start() = 0;
/** Blocks until the activity is terminated */
- // virtual Activity* wait() = 0;
+ virtual Activity* wait() = 0;
/** Blocks until the activity is terminated, or until the timeout is elapsed
* Raises: timeout exception.*/
virtual Activity* wait_for(double timeout) = 0;
void add_successor(AnyActivity* a)
{
- // XBT_INFO("Adding %s as a successor of %s", get_name(), a->get_name());
successors_.push_back(a);
a->add_dependency_on(static_cast<AnyActivity*>(this));
}
void add_dependency_on(AnyActivity* a) { dependencies_.insert({a}); }
void remove_dependency_on(AnyActivity* a) { dependencies_.erase(a); }
bool has_dependencies() { return not dependencies_.empty(); }
- void on_activity_done()
+ void release_dependencies()
{
while (has_successors()) {
AnyActivity* b = get_successor();
return static_cast<AnyActivity*>(this);
}
- virtual AnyActivity* wait()
- {
- static_cast<AnyActivity*>(this)->wait();
- on_activity_done();
- return static_cast<AnyActivity*>(this);
- }
-
AnyActivity* set_name(const std::string& name)
{
xbt_assert(get_state() == State::INITED, "Cannot change the name of an activity after its start");
bool Exec::test()
{
- xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
+ xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING ||
+ state_ == State::FINISHED);
if (state_ == State::FINISHED)
return true;
- if (state_ == State::INITED)
- this->start();
+ if (state_ == State::INITED || state_ == State::STARTING)
+ this->vetoable_start();
if (simcall_execution_test(pimpl_)) {
state_ = State::FINISHED;
simcall_execution_wait(pimpl_, timeout);
state_ = State::FINISHED;
on_completion(*Actor::self(), *this);
+ this->release_dependencies();
return this;
}