From f2159d14bbe00762b63461d06a716754d2c86914 Mon Sep 17 00:00:00 2001 From: knokko Date: Tue, 13 Feb 2024 11:08:22 +0100 Subject: [PATCH] Fix potential concurrency issue --- .../src/main/java/com/github/knokko/update/UpdateLoop.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/implementation/src/main/java/com/github/knokko/update/UpdateLoop.java b/implementation/src/main/java/com/github/knokko/update/UpdateLoop.java index bd80249..5452995 100644 --- a/implementation/src/main/java/com/github/knokko/update/UpdateLoop.java +++ b/implementation/src/main/java/com/github/knokko/update/UpdateLoop.java @@ -100,10 +100,11 @@ public void stop() { } private long determineSleepTime(long currentTime) { - long nextUpdateAt = reference.time + reference.counter * period; + Reference currentReference = reference; + long nextUpdateAt = currentReference.time + currentReference.counter * period; long nextSleepTime = nextUpdateAt - currentTime; - if (-nextSleepTime > maximumBacklog) reference.time += -nextSleepTime - maximumBacklog; + if (-nextSleepTime > maximumBacklog) currentReference.time += -nextSleepTime - maximumBacklog; return nextSleepTime / 1000_000L; }