Why dispatch_sync( ) call on main queue is blocking the main queue?

前端 未结 5 2097
花落未央
花落未央 2020-12-19 11:17

I know this is not a strong question but I have to clear my mind on this concept.

I have defined myBlock as follows.

void(^myBlock)(v         


        
5条回答
  •  悲哀的现实
    2020-12-19 12:06

    There is only one main queue. In your first example, viewDidLoad is running on it. You then tell viewDidLoad to wait (i.e. "sync") on something else that's going to run on the main queue. They both can't be on it at exactly the same time.

    In your second example, it's the concurrent queue that's being told to wait. That's not a problem because by doing dispatch_async, viewWillLoad is giving up the main queue and making it available for your block to run.

提交回复
热议问题