From 280f877145dffbf74e28605ab3d0dd9afdb1c5b2 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Mon, 25 Mar 2024 11:59:18 +0200 Subject: fix atomicarc increment (#23427) The fix to the atomicArc looks to use `-1` as the check value from the `SharedPtr` solution. However, it should be `-rcIncrement` since the refcount is bit shifted in ARC/ORC. I discovered this playing around doing atomic updates of refcounts in a user library. Related to https://github.com/nim-lang/Nim/issues/22711 @ringabout I believe you ported the sharedptr fix? --- lib/system/arc.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/arc.nim b/lib/system/arc.nim index 99c892676..d001fcaa5 100644 --- a/lib/system/arc.nim +++ b/lib/system/arc.nim @@ -221,7 +221,7 @@ proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} = when defined(gcAtomicArc) and hasThreadSupport: # `atomicDec` returns the new value - if atomicDec(cell.rc, rcIncrement) == -1: + if atomicDec(cell.rc, rcIncrement) == -rcIncrement: result = true when traceCollector: cprintf("[ABOUT TO DESTROY] %p\n", cell) -- cgit 1.4.1-2-gfad0