From ce852584890c76fd2418a79f406e6b3ec302fbf5 Mon Sep 17 00:00:00 2001 From: Florian Schmaus <flow@cs.fau.de> Date: Tue, 4 May 2021 12:00:44 +0200 Subject: [PATCH] [LAWS] Set fiber affinity *before* dispatching it, not after --- emper/strategies/laws/LawsDispatcher.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/emper/strategies/laws/LawsDispatcher.cpp b/emper/strategies/laws/LawsDispatcher.cpp index 8044fb40..12af9af8 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); -- GitLab