- if (smx_ctx_thread_sem)
- xbt_os_sem_release(smx_ctx_thread_sem);
- xbt_os_sem_release(this->end_);
+ xbt_assert(not this->is_maestro());
+ this->yield();
+
+ ThreadContext* maestro = static_cast<ThreadContext*>(simix_global->maestro_->context_.get());
+ maestro->end_.acquire();
+
+ Context::set_current(nullptr);
+}
+
+// SerialThreadContext
+
+void SerialThreadContext::run_all()
+{
+ for (smx_actor_t const& actor : simix_global->actors_to_run) {
+ XBT_DEBUG("Handling %p", actor);
+ ThreadContext* 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(SIMIX_context_get_nthreads());
+}
+
+void ParallelThreadContext::finalize()
+{
+ delete thread_sem_;
+ thread_sem_ = nullptr;
+}
+
+void ParallelThreadContext::run_all()
+{
+ for (smx_actor_t const& actor : simix_global->actors_to_run)
+ static_cast<ThreadContext*>(actor->context_.get())->release();
+ for (smx_actor_t const& actor : simix_global->actors_to_run)
+ static_cast<ThreadContext*>(actor->context_.get())->wait();
+}