Adjust the docs for Mutex.withLockIfAvailable() re: spurious failures.

This PR adjusts the documentation for `Mutex.withLockIfAvailable()` to clarify
that it is not subject to spurious failures. The C11 and C++11 specs for their
respective `tryLock()` APIs allow for spurious failures, but our implementations
and those of every other similar API I've found don't use weak `cmpxchg`s and
don't spuriously fail.
This commit is contained in:
Jonathan Grynspan
2025-11-13 14:04:44 -05:00
parent 3545603e1c
commit 09887f16c8

View File

@@ -120,8 +120,13 @@ extension Mutex where Value: ~Copyable {
/// as it will only be executed if the calling thread acquires
/// the lock.
///
/// - Returns: The return value, if any, of the `body` closure parameter
/// or nil if the lock couldn't be acquired.
/// - Returns: The return value, if any, of the `body` closure parameter or
/// `nil` if the lock couldnt be acquired.
///
/// - Note: This function cannot spuriously fail to acquire the lock. The
/// behavior of similar functions in other languages (such as C's
/// `mtx_trylock()`) is platform-dependent and may differ from Swift's
/// behavior.
@available(SwiftStdlib 6.0, *)
@_alwaysEmitIntoClient
@_transparent