From f877ff8dde1163cb375129d59ca318a9973be5e1 Mon Sep 17 00:00:00 2001 From: benwulfe Date: Mon, 30 Jan 2017 15:40:59 -0800 Subject: [PATCH] Update ScheduledThreadPoolExecutor.cs There is a small chance that -1 could be a calculated result for the next time to wait, which would result in an inifinite wait duration (instead of 0). Since AddTask will not Set if the new task isnt added in the first slot, this has the result of completely stalling the scheduler. --- Sharpen/Sharpen/ScheduledThreadPoolExecutor.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sharpen/Sharpen/ScheduledThreadPoolExecutor.cs b/Sharpen/Sharpen/ScheduledThreadPoolExecutor.cs index 50f2b6d91a0..ed67bdbf644 100755 --- a/Sharpen/Sharpen/ScheduledThreadPoolExecutor.cs +++ b/Sharpen/Sharpen/ScheduledThreadPoolExecutor.cs @@ -197,8 +197,6 @@ void SchedulerThread () { int nextWait = ST.Timeout.Infinite; while (true) { - if (nextWait != ST.Timeout.Infinite) - nextWait = Math.Max (0, nextWait); newTask.WaitOne (nextWait); lock (tasks) { DateTime now = DateTime.Now; @@ -209,7 +207,7 @@ void SchedulerThread () n--; } if (n < tasks.Count) - nextWait = (int) Math.Ceiling ((tasks[n].DueTime - DateTime.Now).TotalMilliseconds); + nextWait = Math.Max (0, (int) Math.Ceiling ((tasks[n].DueTime - DateTime.Now).TotalMilliseconds)); else nextWait = ST.Timeout.Infinite; }