X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/465dac153770a28f3a334705a06a1ee7a457c965..0f452f653f11ac26c21fff61b8d17c6137fcba85:/src/kernel/context/ContextThread.cpp diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index 64188a62f8..171e32e62e 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -22,8 +22,7 @@ namespace context { // ThreadContextFactory -ThreadContextFactory::ThreadContextFactory() - : ContextFactory("ThreadContextFactory"), parallel_(SIMIX_context_is_parallel()) +ThreadContextFactory::ThreadContextFactory() : ContextFactory(), parallel_(SIMIX_context_is_parallel()) { if (parallel_) ParallelThreadContext::initialize(); @@ -76,9 +75,10 @@ ThreadContext::ThreadContext(std::function code, void_pfn_smxprocess_t c ThreadContext::~ThreadContext() { - if (this->thread_) /* If there is a thread (maestro don't have any), wait for its termination */ + if (this->thread_) { /* Maestro don't have any thread */ thread_->join(); - delete thread_; + delete thread_; + } } void *ThreadContext::wrapper(void *param) @@ -100,16 +100,17 @@ void *ThreadContext::wrapper(void *param) try { (*context)(); + if (not context->is_maestro()) { // Just in case somebody detached maestro + context->Context::stop(); + context->stop_hook(); + } } catch (StopRequest const&) { - XBT_DEBUG("Caught a StopRequest"); + XBT_DEBUG("Caught a StopRequest in Thread::wrapper"); xbt_assert(not context->is_maestro(), "Maestro shall not receive StopRequests, even when detached."); } catch (simgrid::Exception const& e) { 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(); @@ -117,6 +118,8 @@ void *ThreadContext::wrapper(void *param) stack.ss_flags = SS_DISABLE; sigaltstack(&stack, nullptr); #endif + XBT_DEBUG("Terminating"); + Context::set_current(nullptr); return nullptr; } @@ -145,6 +148,7 @@ void ThreadContext::yield() void ThreadContext::stop() { Context::stop(); + stop_hook(); throw StopRequest(); }