From f5e280f1475eed1e554932aa3b3c9ae88223a974 Mon Sep 17 00:00:00 2001 From: Sebastiaan Koppe Date: Mon, 18 Jan 2021 14:50:17 +0100 Subject: [PATCH] We really need to do the load_state again after a failed casWeak The original c++ source uses compare_exchange_weak which loads the value if the compare failes. casWeak doesn't load it on failure. --- source/concurrency/stoptoken.d | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/concurrency/stoptoken.d b/source/concurrency/stoptoken.d index 358f053..b1f865e 100644 --- a/source/concurrency/stoptoken.d +++ b/source/concurrency/stoptoken.d @@ -209,14 +209,12 @@ public: bool try_add_callback(StopCallback cb, bool incrementRefCountIfSuccessful) nothrow @safe { ulong oldState; - goto load_state; do { - goto check_state; + goto load_state; do { spin_yield(); load_state: oldState = state_.atomicLoad!(MemoryOrder.acq); - check_state: if (is_stop_requested(oldState)) { cb.execute(); return false;