Member-only story
GCD Barriers in Swift: Synchronising Concurrent Tasks
Optimising
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 14.2, and Swift 5.7.2
Prerequisites:
- You will be expected to be aware of how to make a Single View Application
- Some familiarity with GCD and concurrency would be useful for the reader
Keywords and Terminology:
Grand Central Dispatch (GCD): Apple’s high-level API for managing concurrency on macOS, iOS, and other Apple platforms. It provides a way to manage concurrent tasks using dispatch queues, which can be used to execute tasks asynchronously and in a thread-safe manner.
Barrier: A synchronisation tool that ensures only one task accesses a shared resource at a given time.
GCD and barriers
Introduction
GCD is a low-level API for managing concurrent operations, and used well will help make your application smooth and response.
We might use any particular queue to dispatch a task. Here we are using the global queue to do so:
// Async Dispatch
DispatchQueue.global().async {
// Perform task…