[libc-commits] [libc] [libc][thread] detect self-join and mutual-join deadlock (PR #194891)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Apr 29 13:48:34 PDT 2026
================
@@ -340,6 +342,24 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
}
int Thread::join(ThreadReturnValue &retval) {
+ if (self.attrib) {
+ // Reject self join.
+ if (self.attrib == attrib)
+ return EDEADLK;
+
+ // Do a best-effort check of concurrent/repeated join.
+ ThreadAttributes *expected = nullptr;
+ if (!attrib->joiner.compare_exchange_strong(expected, self.attrib,
+ cpp::MemoryOrder::ACQ_REL))
+ return EINVAL;
+
+ // Reject mutual join.
+ if (self.attrib->joiner.load(cpp::MemoryOrder::ACQUIRE) == attrib) {
----------------
michaelrj-google wrote:
nit: From what I understand this is where the `joiner` is set, as well as where it's compared. It's a little unclear, could you add a comment noting that this is where the variable is set?
https://github.com/llvm/llvm-project/pull/194891
More information about the libc-commits
mailing list