Why is the latest version using queue. sync (flags:. barrier) in chapters 5 concurrent problems: Dispatch Barrier, while the old version of Concurrency_by-Tutorials_v2.1.0 used threadSafeCountQueue. sync (flags:. barrier), because the old version should not be used in this way. I hope to answer my doubts
The difference you’re seeing between threadSafeCountQueue.sync(flags:.barrier)
in the old version and queue.sync(flags:.barrier)
in the latest version likely reflects changes in Swift and the Grand Central Dispatch (GCD) API over time.
In earlier versions of Swift and GCD, DispatchQueue.concurrentPerform
was used to parallelize work across multiple threads. The threadSafeCountQueue
you mentioned was likely a custom concurrent queue implemented to ensure thread safety when accessing shared resources.
However, as Swift and GCD have evolved, newer and more efficient ways of handling concurrency have emerged. The queue.sync(flags:.barrier)
syntax you’re seeing in the latest version likely indicates the use of a concurrent queue with a barrier, which provides a more efficient and idiomatic way of achieving the same synchronization and parallelism.
In essence, the change you’re observing likely reflects advancements in Swift and GCD, with the latest version adopting newer, more efficient concurrency patterns compared to the older version.
Hopefully, you may find this helpful.