Avatar
Avatar
Iceman
@swift-main + swiftc -swift-version 6 import Synchronization final class Foo { var value = 0 } nonisolated func main() async { let mutex = Mutex(Foo()) let foo = mutex.withLock { $0 } for _ in 0..<10000 { Task.detached { let foo = mutex.withLock { $0 } foo.value += 1 } } foo.value += 1 try? await Task.sleep(for: .milliseconds(10)) print(foo.value) } await main()
swiftNightly BOT 10/8/2025 3:12 AM
exit status 1 with stderr:<stdin>:12:10: error: sending value of non-Sendable type '() async -> ()' risks causing data races [#SendingRisksDataRace] 10 | let foo = mutex.withLock { $0 } 11 | for _ in 0..<10000 { 12 | Task.detached { | |- error: sending value of non-Sendable type '() async -> ()' risks causing data races [#SendingRisksDataRace] | |- note: Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code | `- note: access can happen concurrently 13 | let foo = mutex.withLock { $0 } 14 | foo.value += 1 [#SendingRisksDataRace]: <https://docs.swift.org/compiler/documentation/diagnostics/sending-risks-data-race>