Avatar
norio_nomura 3/9/2018 12:11 PM
この場合、排他制御が無いとどうなるかを知る方が早いかな。
12:12 PM
import Foundation let count = 10000 var array1 = [Int?](repeating: nil, count: count) DispatchQueue.concurrentPerform(iterations: count) { idx in array1[idx] = idx } print(array1.flatMap({ $0 }).count == count) // false var array2 = [Int?](repeating: nil, count: count) let queue = DispatchQueue.init(label: "test") DispatchQueue.concurrentPerform(iterations: count) { idx in queue.sync { array2[idx] = idx } } print(array2.flatMap({ $0 }).count == count) // true