0

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 !

2
  • 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 Commented Sep 14, 2015 at 6:52
  • There should be some response right ! because the question was thrown at me in a iOS written interview test Commented Sep 18, 2015 at 11:10

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.