Asynchronous Development
There are two parts to all thread methods and functionality.
- You have to tell the program what you want to happen on the current thread (whether it halts: sync or continues: async) and
- 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