Example:
dispatch_sync(someConcurrentQueue, ^(){
dispatch_apply(5,someConcurrentQueue, ^(size_t i){
// do some non-thread safe operation
});
});
I decided to test this out and noticed that the non-thread safe operation performed as expected. However, when I called dispatch_sync using a global queue, things quickly deteriorated.
So my questions are:
1. What is happening under the hood with a call like that?
2. Is every iteration of dispatch_apply being preemptively scheduled on its own thread then executing serially?
3. If the answer to 2 is yes, would doing this inside of an infinite loop be a performance increase? The reasoning being that operation could start executing as soon as the last one finished instead of looping again.
This is roughly the same as:
The operations would be enqueued on the same queue, which thread the code will run on is more of an implementation detail. As such if you did this in an infinite loop it would look something like this:
As your next
dispatch_syncwill get executed oncedispatch_applyhas been scheduled (not executed) your queue will increase in size very quickly.