From 45a58e4a728a699fdedc05d8163d91749baf73fa Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Mon, 22 Feb 2021 21:27:49 +0100
Subject: [PATCH] [Runtime] Fix skipWakeupThreshold value

Adjust to sem_getvalue() being allowed to return 0 if there are
waiting workers.
---
 emper/Runtime.hpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/emper/Runtime.hpp b/emper/Runtime.hpp
index f52a5843..5e417ab9 100644
--- a/emper/Runtime.hpp
+++ b/emper/Runtime.hpp
@@ -84,7 +84,14 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
 			// This is sound because wakeupSleepingWorkers() is called from a active
 			// worker which will observe its own new work in its next dispatchLoop before
 			// going to sleep.
-			skipWakeupThreshold = -1;
+
+			// Note that sem_getvalue() is allowed to return 0 if there are
+			// waiting workers, hence we need to set the threshold also to
+			// 0. This has the disadvantage that we will perform one
+			// unnecessary sem_post. If we ever switch the wakeupSem
+			// implementation, then the skipWakeupThreshold value should be
+			// reviewed and potentially changed to '-1'.
+			skipWakeupThreshold = 0;
 		}
 
 		int semValue;
-- 
GitLab