Member-only story
Avoid Deadlock with Semaphores
Stop-Wait-Go
You might well be familar with GCD, but what if you wish to make sure that you never enter a deadlocked state?
Read on!
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.4.1, and Swift 5.2.2
Updated for Xcode 11.5
The importance
The Readers-Writers Problem is an important one in Computer Science.
In your iOS application you may have several threads that wish to access a shared resource (the cannonical example for this is a file).
You would not want to be in a situation where the file can be written on at the same time as it is being read — imagine that *during* the reading process the file is written. This would mean that we couldn’t be certain of what we were reading; perhaps half of the original file and half of the updated file — what a disaster!