10) { _ in for _ in 0 ..< 1_000_000 { counter += 1 } } print(counter) Mutation of captured var ‘counter’ in concurrently-executing code 👈Swift 5Ͱ࣮ߦ͢Δͱ10_000_000ʹͳΒͳ͍
= AtomicUpdateOrdering.relaxed atomic.add(1, ordering: ordering) Ordering argument must be a static method or property of ‘… 👆ઐ༻ͷΤϥʔϝοηʔδ͕͋Δ https://github.com/swiftlang/swift/blob/.../stdlib/public/Synchronization/Atomics/AtomicIntegers.swift.gyb#L110 https://github.com/apple/swift-atomics/blob/.../Sources/Atomics/Types/ManagedAtomic.swift#L58 https://github.com/swiftlang/swift/blob/.../test/Sema/diag_constantness_check.swift https://github.com/swiftlang/swift/blob/.../include/swift/AST/DiagnosticsSema.def#L7470-L7472
60 let counter = Atomic(MyCounter(0)) DispatchQueue.concurrentPerform(iterations: 10) { _ in for _ in 0 ..< 1_000_000 { counter } } public struct MyCounter: AtomicRepresentable {...} Capture of 'counter' with non-sendable type 'Atomic<MyCounter>' in a `@Sendable` closure
- Apple Developer • https://developer.apple.com/videos/play/wwdc2024/10136/ • Var of Atomic type is not an error? - #2 by MahdiBM - Using Swift - Swift Forums • https://forums.swift.org/t/var-of-atomic-type-is-not-an-error/69885/2 • ಉظ • https://www.hpcs.cs.tsukuba.ac.jp/~tatebe/lecture/h27/dsys/5-sync.pdf • ϝϞϦϞσϧೖʢSequential ConsistencyͱTotal Store OrderΛཧղ͢Δʣ • https://techblog.lycorp.co.jp/ja/20231216a • Swift ʹಋೖ༧ఆͷ Ownership ػೳͷհ #swtws - Qiita • https://qiita.com/omochimetaru/items/c5f0eabde516e4713367 • How to develop SIL Optimizer in Swift Language • https://gist.github.com/freddi-kit/459297734b37cb51bfb08f74ce944cab • swift-ownership-jp/0176-enforce-exclusive-access-to-memory.md at master · omochi/swift-ownership-jp • https://github.com/omochi/swift-ownership-jp/blob/master/0176-enforce-exclusive-access-to-memory.md 74