Sobes.tech
Junior — Middle

Is mutual blocking inevitable when using synchronization on the main queue?

sobes.tech AI

Answer from AI

Deadlock (deadlock) when using synchronization on the main queue does not necessarily occur, but it can happen with incorrect usage. The main queue is a serial queue, and if you synchronously call code from it that also tries to execute something on the main queue, the thread will be blocked, waiting for itself.

For example, if you call dispatch_sync on the main queue from the main thread, it will lead to a deadlock because the task cannot complete until the current one finishes.

Therefore, synchronous calls on the main queue from the main thread should be avoided. Asynchronous calls or using other queues will help prevent deadlock.

Is mutual blocking inevitable when using… - sobes.tech