Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

nested sync queue inside sync queue not running

let q = DispatchQueue.init(label:"test",qos:.background)
q.sync{
       NSLog("q")
       q.sync {
       NSLog("\(Thread.current.isMainThread) \(Thread.current.name) \(Thread.current.qualityOfService)")
       }
}

Why q.sync inside q.sync not printing out ?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is called deadlock. The inner call q.sync waits for the first q.sync task to complete. The first q.sync task can’t complete because it has an inner q.sync waiting to be dispatched.

That’s the reason why you don’t call DispatchQueue.main.sync {...}

So the inner queue call has to be async in order not to cause deadlocks on serial queues.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading