diff options
author | Ben Gamari <ben@smart-cactus.org> | 2023-03-07 16:07:38 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-03-25 20:23:48 -0400 |
commit | c32abd4b936b3dfc61974ed5915c330fe7ed10d5 (patch) | |
tree | cb23449db519b33c44207dcd0f9aa66a034ad101 | |
parent | c6ec4cd1a94a1b76b7b094d5c92ee605031ecf60 (diff) | |
download | haskell-c32abd4b936b3dfc61974ed5915c330fe7ed10d5.tar.gz |
rts: Fix capability-count check in zeroSlop
Previously `zeroSlop` examined `RtsFlags` to determine whether the
program was single-threaded. This is wrong; a program may be started
with `+RTS -N1` yet the process may later increase the capability count
with `setNumCapabilities`. This lead to quite subtle and rare crashes.
Fixes #23088.
-rw-r--r-- | rts/include/rts/storage/ClosureMacros.h | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/rts/include/rts/storage/ClosureMacros.h b/rts/include/rts/storage/ClosureMacros.h index e005dc5f78..af4d13a198 100644 --- a/rts/include/rts/storage/ClosureMacros.h +++ b/rts/include/rts/storage/ClosureMacros.h @@ -535,9 +535,8 @@ zeroSlop (StgClosure *p, #endif ; - const bool can_zero_immutable_slop = - // Only if we're running single threaded. - RTS_DEREF(RtsFlags).ParFlags.nCapabilities <= 1; + // Only if we're running single threaded. + const bool can_zero_immutable_slop = getNumCapabilities() == 1; const bool zero_slop_immutable = want_to_zero_immutable_slop && can_zero_immutable_slop; |