Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid to call Context::stop() again when a StopRequest was thrown.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 22 Jan 2019 19:48:43 +0000 (20:48 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 22 Jan 2019 19:54:22 +0000 (20:54 +0100)
It's already called just before the exception is thrown by the stop() method
(SwappedContext or ThreadContext).
Asan likes it better when it's called before throwing the exception.

src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextUnix.cpp

index 1bddeb1..6153c41 100644 (file)
@@ -70,13 +70,13 @@ void BoostContext::wrapper(BoostContext::arg_type arg)
 #endif
   try {
     (*context)();
 #endif
   try {
     (*context)();
+    context->Context::stop();
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   } catch (simgrid::Exception const& e) {
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   } catch (simgrid::Exception const& e) {
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
-  context->Context::stop();
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }
index c7a0a1c..84d742c 100644 (file)
@@ -212,14 +212,13 @@ void RawContext::wrapper(void* arg)
   ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
   try {
     (*context)();
   ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
   try {
     (*context)();
+    context->Context::stop();
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   } catch (simgrid::Exception const& e) {
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   } catch (simgrid::Exception const& e) {
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
-  context->Context::stop();
-
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }
index 2037673..205e186 100644 (file)
@@ -100,6 +100,8 @@ void *ThreadContext::wrapper(void *param)
 
   try {
     (*context)();
 
   try {
     (*context)();
+    if (not context->is_maestro()) // Just in case somebody detached maestro
+      context->Context::stop();
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
     xbt_assert(not context->is_maestro(), "Maestro shall not receive StopRequests, even when detached.");
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
     xbt_assert(not context->is_maestro(), "Maestro shall not receive StopRequests, even when detached.");
@@ -107,9 +109,6 @@ void *ThreadContext::wrapper(void *param)
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
-  if (not context->is_maestro()) // Just in case somebody detached maestro
-    context->Context::stop();
-
   // Signal to the caller (normally the maestro) that we have finished:
   context->yield();
 
   // Signal to the caller (normally the maestro) that we have finished:
   context->yield();
 
index 92d9271..88d4710 100644 (file)
@@ -40,13 +40,13 @@ static void smx_ctx_wrapper(int i1, int i2)
   ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
   try {
     (*context)();
   ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
   try {
     (*context)();
+    context->Context::stop();
   } catch (simgrid::kernel::context::Context::StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   } catch (simgrid::Exception const& e) {
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
   } catch (simgrid::kernel::context::Context::StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   } catch (simgrid::Exception const& e) {
     XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
     throw;
   }
-  context->Context::stop();
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }