- Normally code gets executed on main thread, either synchronously or asynchronously.
- So if you write code main.sync
main.sync {
}
3. It will be like
main.async(sync) { //outer loop
main.sync { //inner loop
}
}
4. Because inner loop is sync, it waits outer loop to be done.
5. The outer loop can be done only after the inner loop is done.
6. Main queue is a serial queue.
7. So these two loops wait for each other to be done on serial queue. This is deadlock.
8. Crash occurs
10. So if you use main.sync on concurrent background queue, crash does not occur.
Reference