0
votes

I know you would deadlock by doing this on a serial queue, but I haven't found anything that mentions deadlocking by doing it on a concurrent queue. I just wanted to verify it wont deadlock (it doesn't seem like it would, as it would only block one of the threads on the queue and the task would run on another thread on the same queue)

Also, is it true that you can control order of execution by calling dispatch_sync on a concurrent queue? (It's mentioned here) I don't understand why that would happen, as async vs sync have to do with the caller thread.

1
Thanks, but it's more of a general question rather than a problem I've encountered.rb612
Unless you can absolutely guarantee that not all threads will end up waiting on something at the same time then there is a deadlock risk - how can you guarantee that?Wain

1 Answers

2
votes

This will not deadlock since the dispatched block can start running immediately - it's not a serial queue so it doesn't have to wait for the current block to finish.

But it's still not a good idea. This will block one thread causing the OS to spin up a new one (because it still has free CPU as the thread is sleeping) wasting memory.