File 0747-erts-Fix-proc-unlock-memory-order.patch of Package erlang
From 46ff98a5d5e6cff2ae4ba670de1d0fd233f5cf5a Mon Sep 17 00:00:00 2001
From: Daniel Hryzbil <daniel.hryzbil@ui.com>
Date: Wed, 11 Feb 2026 09:23:35 +0100
Subject: [PATCH] erts: Fix proc unlock memory order
When unlocking a process lock, the atomic store-release operation must
*always* happen to ensure acquire-release semantics of process locks.
It cannot be conditionally skipped.
This fixes a rare issue where some scheduler threads get stuck in a
process lock wait queue. Note that the issue can only occur on
weakly-ordered CPUs such as ARM.
Signed-off-by: Daniel Hryzbil <daniel.hryzbil@ui.com>
---
erts/emulator/beam/erl_process_lock.h | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/erts/emulator/beam/erl_process_lock.h b/erts/emulator/beam/erl_process_lock.h
index 76e8616280..6e967df27f 100644
--- a/erts/emulator/beam/erl_process_lock.h
+++ b/erts/emulator/beam/erl_process_lock.h
@@ -774,15 +774,13 @@ erts_proc_unlock__(Process *p,
/* What p->lock will look like with all non-waited locks released. */
ErtsProcLocks want_lflgs = old_lflgs & (wait_locks | ~locks);
- if (want_lflgs != old_lflgs) {
- ErtsProcLocks new_lflgs =
- ERTS_PROC_LOCK_FLGS_CMPXCHG_RELB_(&p->lock, want_lflgs, old_lflgs);
-
- if (new_lflgs != old_lflgs) {
- /* cmpxchg failed, try again. */
- old_lflgs = new_lflgs;
- continue;
- }
+ ErtsProcLocks new_lflgs =
+ ERTS_PROC_LOCK_FLGS_CMPXCHG_RELB_(&p->lock, want_lflgs, old_lflgs);
+
+ if (new_lflgs != old_lflgs) {
+ /* cmpxchg failed, try again. */
+ old_lflgs = new_lflgs;
+ continue;
}
/* We have successfully unlocked every lock with no waiter. */
--
2.51.0