Suppose I send a task asynchronously to a queue:
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
print("task B")
});
print("task A")
print("task A")
print("task A")
...
}
In any case, can a submitted task interrupt the task from which it was sent? In other words, can it ever happen that “task B” is printed before all “tasks A” are printed?
task A
task B
task A
task A
...
Or GCD guarantees this:
task A
task A
task A
...
task B
Will it matter if the task was sent to the same queue from which dispatch_async is called?
Srđan source
share