[libc-commits] [libc] [libc] Return EBUSY from pthread_mutex_destroy on a locked mutex (PR #239986)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Mon Nov 9 20:18:08 PST 2026
================
@@ -73,8 +73,12 @@ class Mutex final : private RawMutex {
error_checking(is_error_checking), owner(0), lock_count(0) {}
LIBC_INLINE static MutexError destroy(Mutex *lock) {
- LIBC_ASSERT(lock->owner == 0 && lock->lock_count == 0 &&
- "Mutex destroyed while being locked.");
+ // glibc says EBUSY and leaves a locked mutex as it was, except a robust
+ // one, whose owner may have exited. Only recursive and error checking
+ // mutexes record an owner, so the futex word is what tells a locked one.
+ if (!lock->robust && (lock->owner != 0 || lock->lock_count != 0 ||
----------------
SchrodingerZhu wrote:
I think this is a good thing to have but, if I understand it correctly, this error is not specified by POSIX. If we are to pursuit this behavior, this will need a line in our `undefined behavior document`.
And we will need to justify why the exact condition is useful and correct.
cc @michaelrj-google
https://github.com/llvm/llvm-project/pull/239986
More information about the libc-commits
mailing list