Junior — Middle
Can there be cases where using sync call on the main queue does not lead to deadlock?
sobes.tech AI
Answer from AI
Calling sync on the main queue usually leads to a deadlock if called from the main queue itself, as it will wait for a block to finish that cannot start until the current one finishes. However, if the sync call on the main queue is made from another thread (not the main queue), then there will be no deadlock, as the main thread can execute the block and release the call.
Example:
DispatchQueue.main.sync {
// This code will execute without deadlock if called from a background thread
}