void_pfn_smxprocess_t cleanup_func_ = nullptr;
smx_actor_t process_ = nullptr;
public:
+ class StopRequest {
+ };
bool iwannadie;
Context(std::function<void()> code,
static_cast<BoostContext**>(arg.data)[0]->fc_ = arg.fctx;
BoostContext* context = static_cast<BoostContext**>(arg.data)[1];
#endif
- (*context)();
- context->stop();
+ try {
+ (*context)();
+ context->stop();
+ } catch (StopRequest) {
+ XBT_DEBUG("Caught a StopRequest");
+ }
+ context->suspend();
}
inline void BoostContext::smx_ctx_boost_jump_fcontext(BoostContext* from, BoostContext* to)
void BoostSerialContext::stop()
{
BoostContext::stop();
- this->suspend();
+ throw StopRequest();
}
// BoostParallelContext
void BoostParallelContext::stop()
{
BoostContext::stop();
- this->suspend();
+ throw StopRequest();
}
void BoostParallelContext::resume()
void RawContext::wrapper(void* arg)
{
RawContext* context = static_cast<RawContext*>(arg);
- (*context)();
- context->stop();
+ try {
+ (*context)();
+ context->stop();
+ } catch (StopRequest) {
+ XBT_DEBUG("Caught a StopRequest");
+ }
+ context->suspend();
}
RawContext::RawContext(std::function<void()> code,
void RawContext::stop()
{
Context::stop();
- this->suspend();
+ throw StopRequest();
}
void RawContextFactory::run_all()
if (smx_ctx_thread_sem) /* parallel run */
xbt_os_sem_acquire(smx_ctx_thread_sem);
- (*context)();
- context->stop();
+ try {
+ (*context)();
+ context->stop();
+ } catch (StopRequest) {
+ XBT_DEBUG("Caught a StopRequest");
+ }
+#ifndef WIN32
+ stack.ss_flags = SS_DISABLE;
+ sigaltstack(&stack, nullptr);
+#endif
return nullptr;
}
// Signal to the maestro that it has finished:
xbt_os_sem_release(this->end_);
-#ifndef WIN32
- stack_t stack;
- stack.ss_sp = nullptr;
- stack.ss_size = 0;
- stack.ss_flags = SS_DISABLE;
- sigaltstack(&stack, nullptr);
-#endif
- xbt_os_thread_exit(nullptr);
+ throw StopRequest();
}
void ThreadContext::suspend()
-/* Copyright (c) 2009-2015. The SimGrid Team.
+/* Copyright (c) 2009-2017. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
}
memcpy(&context, ctx_addr, sizeof(simgrid::kernel::context::UContext*));
- (*context)();
- context->stop();
+ try {
+ (*context)();
+ context->stop();
+ } catch (simgrid::kernel::context::Context::StopRequest) {
+ XBT_DEBUG("Caught a StopRequest");
+ }
+ context->suspend();
}
namespace simgrid {
void SerialUContext::stop()
{
Context::stop();
- this->suspend();
+ throw StopRequest();
}
void SerialUContext::suspend()
void ParallelUContext::stop()
{
UContext::stop();
- this->suspend();
+ throw StopRequest();
}
/** Run one particular simulated process on the current thread. */