Asynchronous Development

Notes in Swift

Scott
1 min readJun 16, 2020

There are two parts to all thread methods and functionality.

  1. You have to tell the program what you want to happen on the current thread (whether it halts: sync or continues: async) and
  2. What thread the task goes on.

Thread safety

Wrap reading with a serial queue:

Dispatch_Queue(label: "myQueue").sync { 
// read here
}

Wrap writing with a serial queue:

Dispatch_Queue(label: "myQueue").async(flag: barrier) {
// write here
}

You should apply this to custom objects and when interfacing with arrays.

Threading issues:

  • Deadlocks
  • Race Conditions

Mutexes

DispatchQueue

DispatchSemaphore

--

--

No responses yet