+// SerialThreadContext
+
+void SerialThreadContext::run_all()
+{
+ const auto& to_run = EngineImpl::get_instance()->get_actors_to_run();
+ for (smx_actor_t const& actor : to_run) {
+ XBT_DEBUG("Handling %p", actor);
+ auto* context = static_cast<ThreadContext*>(actor->context_.get());
+ context->release();
+ context->wait();
+ }
+}
+
+// ParallelThreadContext
+
+xbt::OsSemaphore* ParallelThreadContext::thread_sem_ = nullptr;
+
+void ParallelThreadContext::initialize()
+{
+ thread_sem_ = new xbt::OsSemaphore(get_nthreads());
+}
+
+void ParallelThreadContext::finalize()
+{
+ delete thread_sem_;
+ thread_sem_ = nullptr;
+}
+
+void ParallelThreadContext::run_all()
+{
+ const auto& to_release = EngineImpl::get_instance()->get_actors_to_run();
+ for (smx_actor_t const& actor : to_release)
+ static_cast<ThreadContext*>(actor->context_.get())->release();
+ const auto& to_wait = EngineImpl::get_instance()->get_actors_to_run();
+ for (smx_actor_t const& actor : to_wait)
+ static_cast<ThreadContext*>(actor->context_.get())->wait();
+}
+
+void ParallelThreadContext::start_hook()
+{
+ if (not is_maestro()) /* parallel run */
+ thread_sem_->acquire();
+}
+
+void ParallelThreadContext::yield_hook()
+{
+ if (not is_maestro()) /* parallel run */
+ thread_sem_->release();
+}
+
+XBT_PRIVATE ContextFactory* thread_factory()
+{
+ XBT_VERB("Activating thread context factory");
+ return new ThreadContextFactory();
+}
+} // namespace context
+} // namespace kernel
+} // namespace simgrid