From c4f055b70f68bb462cefb9e4ecea8a3d5320dd0d Mon Sep 17 00:00:00 2001 From: Takishipp Date: Tue, 24 Oct 2017 16:32:11 +0200 Subject: [PATCH 1/1] suggested solution tu use simix through a function --- examples/s4u/actor-yield/s4u-actor-yield.cpp | 3 ++- include/simgrid/s4u/Actor.hpp | 4 ++++ src/s4u/s4u_actor.cpp | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/s4u/actor-yield/s4u-actor-yield.cpp b/examples/s4u/actor-yield/s4u-actor-yield.cpp index b5a5d92f01..6e79dc6c6b 100644 --- a/examples/s4u/actor-yield/s4u-actor-yield.cpp +++ b/examples/s4u/actor-yield/s4u-actor-yield.cpp @@ -28,8 +28,9 @@ public: } void operator()() { + simgrid::s4u::ActorPtr actor; for (int i = 0; i < number_of_yields; i++) - simgrid::simix::kernelImmediate([] { /* do nothing*/ }); + actor->yield(); XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields); } }; diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index eef1611123..b4e58c9ece 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -218,6 +218,8 @@ public: /** Resume a suspended process by resuming the task on which it was waiting for the completion. */ void resume(); + void yield(); + /** Returns true if the process is suspended. */ int isSuspended(); @@ -349,6 +351,8 @@ template inline void sleep_for(std::chrono::durationsuspended; }); } +void Actor::yield() +{ + simgrid::simix::kernelImmediate([] { /* do nothing*/ }); +} + void Actor::setKillTime(double time) { simcall_process_set_kill_time(pimpl_,time); } -- 2.20.1