From bbabe60c67ae4ddb0f04cdc78ed5c0820176d354 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Tue, 17 Nov 2015 15:59:27 +0000 Subject: [PATCH] Don't become ready before entering a waiting state. The waiting is done by testing readiness before waiting so there is a window when nothing is waiting (probably near the end of the sort), but we are still reading other stacks, which then get marked as ready releasing the ready wait, so it's then just a timing game as to whether the waiting wait is incremented in time... 99.999999% of the time it is. --- src/space.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/space.c b/src/space.c index e71486fca3..1b9784d4d7 100644 --- a/src/space.c +++ b/src/space.c @@ -601,10 +601,10 @@ void space_do_parts_sort() { space_sort_struct.stack[qid].j = jj; space_sort_struct.stack[qid].min = min; space_sort_struct.stack[qid].max = pivot; - space_sort_struct.stack[qid].ready = 1; if (atomic_inc(&space_sort_struct.waiting) >= space_sort_struct.stack_size) error("Qstack overflow."); + space_sort_struct.stack[qid].ready = 1; } /* Recurse on the right? */ @@ -625,10 +625,10 @@ void space_do_parts_sort() { space_sort_struct.stack[qid].j = j; space_sort_struct.stack[qid].min = pivot + 1; space_sort_struct.stack[qid].max = max; - space_sort_struct.stack[qid].ready = 1; if (atomic_inc(&space_sort_struct.waiting) >= space_sort_struct.stack_size) error("Qstack overflow."); + space_sort_struct.stack[qid].ready = 1; } /* Recurse on the left? */ -- GitLab