From 8b4cd5a3f303d1e13a1a5e14cecf993a4b9b5578 Mon Sep 17 00:00:00 2001 From: Michael Freundorfer Date: Wed, 11 Mar 2026 10:07:26 +0100 Subject: [PATCH] Fix auto reset event signal deadlock The status variables need to be updated every iteration, otherwise the thread will spin forever, if another thread waits on the event between the load and the compare exchange, because the old value is never updated. --- core/sync/extended.odin | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/sync/extended.odin b/core/sync/extended.odin index 8566eccc8..58344b740 100644 --- a/core/sync/extended.odin +++ b/core/sync/extended.odin @@ -222,9 +222,10 @@ thread. */ auto_reset_event_signal :: proc "contextless" (e: ^Auto_Reset_Event) { old_status := atomic_load_explicit(&e.status, .Relaxed) - new_status := old_status + 1 if old_status < 1 else 1 for { - if _, ok := atomic_compare_exchange_weak_explicit(&e.status, old_status, new_status, .Release, .Relaxed); ok { + new_status := old_status + 1 if old_status < 1 else 1 + ok: bool + if old_status, ok = atomic_compare_exchange_weak_explicit(&e.status, old_status, new_status, .Release, .Relaxed); ok { break } cpu_relax()