Avatar
write 処理は同期されるけど,write 呼び出しはすぐ抜けられる,という感じなのかと理解してます.
2:13 PM
deadlock なんじゃなくて単純に処理にめっちゃ時間かかってるのかも…🙄
2:15 PM
しばらく待ったら出力されました.そして両方 sync するように書き直したら一瞬で終わりましたw public class SynchronizedDictionary<Key: Hashable, Value> { private var dictionary: [Key: Value] = [:] private let queue = DispatchQueue(label: "shit", qos: .default) public subscript(_ key: Key) -> Value? { get { queue.sync { dictionary[key] } } set { queue.sync { self.dictionary[key] = newValue } } } } var a = SynchronizedDictionary<Int, Int>() let n = 100000 DispatchQueue.concurrentPerform(iterations: n) { i in a[i] = i } (edited)
2:16 PM
書き込みにそれなりに時間かかるようなケースじゃないとむしろオーバーヘッドになるってことなのかな…🙄 (edited)