From: Arnaud Giersch Date: Thu, 24 Aug 2017 20:45:17 +0000 (+0200) Subject: Avoid sending address of local variables. X-Git-Tag: v3_17~152^2~11 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7224ac739b068ae7fc2f1a811eb7ee6410e1f7fe?ds=sidebyside Avoid sending address of local variables. This should fix the problem introduced by commit e2334f2600f6d03f43a79f9c3dc43c2fff21e115. --- diff --git a/examples/s4u/app-masterworker/s4u_app-masterworker.cpp b/examples/s4u/app-masterworker/s4u_app-masterworker.cpp index 04102b739c..c0ce006b50 100644 --- a/examples/s4u/app-masterworker/s4u_app-masterworker.cpp +++ b/examples/s4u/app-masterworker/s4u_app-masterworker.cpp @@ -41,17 +41,15 @@ public: number_of_tasks, mailbox->getName()); /* - Send the computation amount to the @ref worker */ - mailbox->put(static_cast(&comp_size), comm_size); + mailbox->put(new double(comp_size), comm_size); } XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over."); for (int i = 0; i < workers_count; i++) { /* - Eventually tell all the workers to stop by sending a "finalize" task */ mailbox = simgrid::s4u::Mailbox::byName(std::string("worker-") + std::to_string(i % workers_count)); - double finalize = -1; - mailbox->put(static_cast(&finalize), 0); + mailbox->put(new double(-1.0), 0); } - simgrid::s4u::this_actor::sleep_for(.1); // Grace time to ensure everyone finishes. } }; @@ -71,14 +69,16 @@ public: void operator()() { while (1) { /* The worker waits in an infinite loop for tasks sent by the \ref master */ - double* comp_size = static_cast(mailbox->get()); - xbt_assert(comp_size != nullptr, "MSG_task_get failed"); - if (*comp_size < 0) { /* - Exit if 'finalize' is received */ + double* task = static_cast(mailbox->get()); + xbt_assert(task != nullptr, "mailbox->get() failed"); + double comp_size = *task; + delete task; + if (comp_size < 0) { /* - Exit when -1.0 is received */ XBT_INFO("I'm done. See you!"); break; } /* - Otherwise, process the task */ - simgrid::s4u::this_actor::execute(*comp_size); + simgrid::s4u::this_actor::execute(comp_size); } } }; diff --git a/examples/s4u/app-masterworker/s4u_app-masterworker.tesh b/examples/s4u/app-masterworker/s4u_app-masterworker.tesh index ff2092d8bc..f9b20df3fa 100644 --- a/examples/s4u/app-masterworker/s4u_app-masterworker.tesh +++ b/examples/s4u/app-masterworker/s4u_app-masterworker.tesh @@ -31,6 +31,6 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u_app-masterworker$EXEEXT ${srcdir:=.}/small_pla > [ 4.057541] (worker@Jupiter) I'm done. See you! > [ 4.083249] (worker@Fafard) I'm done. See you! > [ 4.931805] (worker@Ginette) I'm done. See you! +> [ 5.094868] (maestro@) Simulation time 5.09487 > [ 5.094868] (worker@Bourassa) I'm done. See you! -> [ 5.194868] (maestro@) Simulation time 5.19487