__sanitizer_finish_switch_fiber(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
#endif
try {
- sthread_enable();
+ const SThreadGuard sthread_guard;
(*context)();
- sthread_disable();
context->stop();
} catch (simgrid::ForcefulKillException const&) {
- sthread_disable();
XBT_DEBUG("Caught a ForcefulKillException");
} catch (simgrid::Exception const& e) {
- sthread_disable();
XBT_INFO("Actor killed by an uncaught exception %s", boost::core::demangle(typeid(e).name()).c_str());
throw;
}
/** Maestro wants to run all ready actors */
void SwappedContextFactory::run_all(std::vector<actor::ActorImpl*> const& actors_list)
{
+ const SThreadGuard sthread_guard;
const auto* engine = EngineImpl::get_instance();
/* This function is called by maestro at the beginning of a scheduling round to get all working threads executing some
* stuff It is much easier to understand what happens if you see the working threads as bodies that swap their soul
// Save my current soul (either maestro, or one of the minions) in a thread-specific area
worker_context_ = old;
}
- sthread_enable();
// Switch my soul and the actor's one
Context::set_current(this);
old->swap_into(this);
if (i < engine->get_actor_to_run_count()) {
/* Actually swap into the next actor directly without transiting to maestro */
XBT_DEBUG("Run next actor");
- sthread_enable();
next_context = static_cast<SwappedContext*>(engine->get_actor_to_run_at(i)->context_.get());
} else {
/* all processes were run, actually return to maestro */
XBT_DEBUG("No more actors to run");
- sthread_disable();
next_context = factory_.maestro_context_;
}
}
}
#endif
+#if defined(__cplusplus)
+// Helper class using RAII to enable/disable sthread
+class SThreadGuard {
+public:
+ SThreadGuard() { sthread_enable(); }
+ SThreadGuard(const SThreadGuard&) = delete;
+ SThreadGuard& operator=(const SThreadGuard&) = delete;
+ ~SThreadGuard() { sthread_disable(); }
+};
+#endif
+
#endif
zone->seal();
/* Launch the user's main() on an actor */
- sthread_enable();
+ const SThreadGuard sthread_guard;
sg4::ActorPtr main_actor = sg4::Actor::create("main thread", lilibeth, raw_main, argc, argv, envp);
sg4::Engine::get_instance()->run();
- sthread_disable();
XBT_INFO("All threads exited. Terminating the simulation.");
return 0;
if (SMPI_is_inited())
SMPI_thread_create();
#endif
- sthread_enable();
+ const SThreadGuard sthread_guard;
user_function(param);
- sthread_disable();
},
start_routine, arg);