From the course: iOS Development: Architecture

Unlock the full course today

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

Deadlocks

Deadlocks

From the course: iOS Development: Architecture

Start my 1-month free trial

Deadlocks

- [Instructor] Note that submitting a task synchronously through the main queue causes a deadlock. Actually, that's true for any serial queue. Calling sync from a task that is executing on the same queue will deadlock the serial queue. To understand the cause of the deadlock, let's inspect the use case. Say we want to execute the task synchronously on the main queue. I'm going to add a call to our view did load method. So I call dispatch queue main and execute it synchronously. Let's do some basic stuff. We'll only print a lot to the console. Let's try to run the app. We see an error. Now let's take a closer look. The call stack shows that the last function called before the crash was dispatch sync wait. The assembly view contains a warning which states: bug in client of libdispatch dispatch sync called on queue already owned by current thread. So this is what happens behind the scenes. First, the sync method submits the block to the main queue for execution. The main queue is serial,…

Contents