Search code examples
iosqueuedispatch-async

dispatch_Async serial queue


I couldn't guess the output of it.

dispatch_async(serial_queue,^{NSlog(@"1");});

NSlog(@"2");

dispatch_async(serial_queue,^{NSlog(@"3");});

NSlog(@"4");

AFAIK

The output is

1

2

3

4

But I am not sure !

Can anybody explain If I am wrong !


Solution

  • Although the interleaving of the operations may not be known, you can see that there are two streams. The first is logging from a serial queue, the other is just plain NSLog.

    What you can say about the order is that 1 will precede 3 and 2 will precede 4