dispatch_async vs. dispatch_sync using Serial Queues in Grand Central Dispatch

后端 未结 3 852
不知归路
不知归路 2020-12-08 00:46

OK, I love Grand Central Dispatch and after using it with relative success but this is something I don\'t fully understand.

Suppose I have created my own serial queu

3条回答
  •  旧时难觅i
    2020-12-08 01:36

    Serial Queue can only run a single task at a time,irrespective of sync or async. Serial queues are allocated only one thread. This will be easier to understand using the below example -

    Suppose there are 2 Queues A and B running tasks T1 and T2 respectively and T1 is being executed asynchronously. If control passes from A to B and B runs T2 synchronously then till the time the T2(block of code in the dispatch_sync block) completes execution T1 will be blocked. When T2 completes then T1 will resume it's execution.

提交回复
热议问题