Member-only story

GCD Barriers in Swift: Synchronising Concurrent Tasks

Optimising

Steven Curtis
4 min readMar 27, 2023
Photo by Gabriel Komorov on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 14.2, and Swift 5.7.2

Prerequisites:

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…

--

--

Responses (2)