Concurrency's Past: Threads

Episode #190 • May 23, 2022 • Subscriber-Only

To better understand Swift’s concurrency tools, let’s first look to the past, starting with threads. Threads are a tool most developers don’t reach for these days, but are important to understand, and the way they solve problems reverberate even in today’s tools.

Threads
Introduction
00:05
Thread basics
01:28
Priority and cancellation
08:13
Thread dictionaries
13:40
Problems: coordination
23:22
Problems: expensiveness
29:10
Problems: data races
40:33
Next time: concurrency's present
51:59

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Introduction

Just a little over 9 months ago, Swift 5.5 was released and with it came an all new suite of tools for tackling concurrency. We very briefly touched upon some of these tools in past episodes, like when we explored the new .refreshable view modifier in SwiftUI for adding pull-to-refresh to any view.

That exploration was interesting, but also a little superficial. We are ready to dive much deeper into Swift concurrency, and the main reason we want to do this now is because we are also ready to start more deeply integrating Swift’s concurrency tools into the Composable Architecture. In order to do that in the best way possible we are going to need understand a number of concurrency topics, many of which are quite subtle and tricky.

In this series of episodes we want to provide an introduction to most of the new tools that Swift has given us for modeling concurrency. The way we are going to do this is through a lens focused on the past. Apple platforms have a rich history of concurrency tools, from threads to dispatch queues, and most recently, Combine publishers. In order to understand why Swift’s modern concurrency APIs were designed the way they are, and what problems they try to fix, we must know how we got to this point. What did the previous tools excel at, and what were their faults? This will make it easier for us to learn how to use Swift’s new tools, understand why they sometimes don’t work the way we expect, and overall we will be more proficient at using the new APIs.

This episode is for subscribers only.

Subscribe to Point-Free

Access this episode, plus all past and future episodes when you become a subscriber.

See plans and pricing

Already a subscriber? Log in

References

Threading Programming Guide

Apple

Threads are one of several technologies that make it possible to execute multiple code paths concurrently inside a single application. Although newer technologies such as operation objects and Grand Central Dispatch (GCD) provide a more modern and efficient infrastructure for implementing concurrency, OS X and iOS also provide interfaces for creating and managing threads.

This document provides an introduction to the thread packages available in OS X and shows you how to use them. This document also describes the relevant technologies provided to support threading and the synchronization of multithreaded code inside your application.

Introducing Swift Atomics

Karoy Lorentey • Thursday Oct 1, 2020

I’m delighted to announce Swift Atomics, a new open source package that enables direct use of low-level atomic operations in Swift code. The goal of this library is to enable intrepid systems programmers to start building synchronization constructs (such as concurrent data structures) directly in Swift.

Downloads