[llvm-branch-commits] Thread Safety Analysis: Add guarded_by_any and pt_guarded_by_any (PR #185173)

Marco Elver via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Mar 7 03:09:59 PST 2026


https://github.com/melver created https://github.com/llvm/llvm-project/pull/185173

Introduce two new attributes with a weaker ownership model than
guarded_by: writing requires all listed capabilities to be held
exclusively, while reading only requires at least one to be held.
This is sound because any writer must hold all capabilities, so
holding any one of them guarantees at least shared (read) access.

This synchronization pattern is frequently used where the underlying
lock implementation does not support real reader locking, and instead
several lock "shards" are used to reduce contention for readers. For
example, the Linux kernel makes frequent use of this pattern [1].

[1] https://lore.kernel.org/all/20250307085204.GJ16878@noisy.programming.kicks-ass.net/





More information about the llvm-branch-commits mailing list