From the course: iOS Development: Threading and Grand Central Dispatch

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

What are deadlocks?

What are deadlocks?

From the course: iOS Development: Threading and Grand Central Dispatch

Start my 1-month free trial

What are deadlocks?

- [Instructor] One of the major issues that can arise in concurrent programs is deadlocks. Deadlocks occur when two threads sharing the same resources are waiting for each other to complete its tasks and release the resource. They are competing for the same resource and this results in a deadlock. Let's look at this diagram form. These cars both need to drive to the other side. However, they're blocking each other. Who will give way and who will let the other one pass? Neither of the cars can move because a car is blocking them and they have now reached a deadlock. And you have a code block executing a task synchronously, other tasks will have to wait until the first task is done. Essentially, this means sync will block the current thread until all the tasks have finished. Let's look at this in code. Here we have a serial queue with two tasks assigned to it, one synchronously, the other asynchronously. If you try to run this…

Contents