Sobes.tech
Junior — Middle

What happens to threads when using the sync function and which thread is blocked during the process?

sobes.tech AI

Answer from AI

The sync function in the context of multithreading (for example, in GCD on iOS) executes a task synchronously, meaning the calling thread is blocked until the task completes. If sync is called from the main thread on a queue that also runs on the main thread, it will lead to a deadlock because the main thread will wait for the task to finish, which cannot start until the main thread is free.

Thus, when using sync, the calling thread is blocked, and the execution of the code is suspended until the task is completed.