Skip to content

Commit 276706e

Browse files
authored
Don't abort on Linux if withLockIfAvailable() is called recursively. (#85448)
On all platforms except Linux, calling `withLockIfAvailable()` recursively just returns `nil`. However, our Linux implementation chooses to abort the process instead. We don't need this inconsistent/destructive behaviour and can just return `nil` as we do elsewhere.
1 parent b570120 commit 276706e

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

stdlib/public/Synchronization/Mutex/LinuxImpl.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ extension _MutexHandle {
235235

236236
// EDEADLK - "The futex word at uaddr is already locked by the caller."
237237
case 35:
238-
// TODO: Replace with a colder function / one that takes a StaticString
239-
fatalError("Attempt to try to lock Mutex in already acquired thread")
238+
return false
240239

241240
// This handles all of the following errors which generally aren't
242241
// applicable to this implementation:

stdlib/public/Synchronization/Mutex/Mutex.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ extension Mutex where Value: ~Copyable {
114114
/// }
115115
/// return try body(&value)
116116
///
117-
/// - Warning: Recursive calls to `withLockIfAvailable` within the
118-
/// closure parameter has behavior that is platform dependent.
119-
/// Some platforms may choose to panic the process, deadlock,
120-
/// or leave this behavior unspecified. This will never
121-
/// reacquire the lock however.
122-
///
123117
/// - Parameter body: A closure with a parameter of `Value`
124118
/// that has exclusive access to the value being stored within
125119
/// this mutex. This closure is considered the critical section

0 commit comments

Comments
 (0)