0
votes

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 !

1
the output should be theoretically unpredictable, since there is no guarantee when the async blocks will execute... but i guess maybe those async blocks execute too quickly for the order to ever be different - Fonix
There should be some response right ! because the question was thrown at me in a iOS written interview test - NaveenKumar

1 Answers

1
votes

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