diff --git a/emper/strategies/laws/LawsDispatcher.cpp b/emper/strategies/laws/LawsDispatcher.cpp index 8044fb404423b1f5bb0725c2d7d6f0eddc60ff73..12af9af83e266482135cbeebef50dd60981b5604 100644 --- a/emper/strategies/laws/LawsDispatcher.cpp +++ b/emper/strategies/laws/LawsDispatcher.cpp @@ -53,11 +53,17 @@ void LawsDispatcher::dispatchLoop() { } } - // The fiber was marked das runnable. Run it now. - dispatch(fiber); - // Update the affinity if one was set. + // Update the affinity if one was set. Note that we do this + // before dispatching the fiber, as the fiber will change the + // affinity towards the current worker as soon as it starts + // executing, i.e. right now. Also, future code may delete the + // affinity buffer as part of the Fiber's run() method, so it + // may not longer be valid after dispatching it. workeraffinity_t* const affinity = getAffinityBuffer(fiber); if (affinity) *affinity = Runtime::getWorkerId(); + + // The fiber was marked das runnable. Run it now. + dispatch(fiber); } recycle(fiber);