设为首页 加入收藏

TOP

iOS学习笔记-死锁deadlock理解
2017-10-12 17:45:48 】 浏览:675
Tags:iOS 学习 笔记 死锁 deadlock 理解

1.首先看一下官方文档的解释,这个block的队列是同步执行的,不像异步,这个方法直到block执行完毕才会返回

2.主线程一旦开启,就要先把自己的代码执行完成之后,才去执行加入到主队列中的任务

Declaration

void dispatch_sync( dispatch_queue_t queue, dispatch_block_t block);

Parameters

queue

The queue on which to submit the block. This parameter cannot be NULL.

block

The block to be invoked on the target dispatch queue. This parameter cannot be NULL.

Discussion

Submits a block to a dispatch queue for synchronous execution. Unlike dispatch_async, this function does not return until the block has finished. Calling this function and targeting the current queue results in deadlock.

死锁原因:

a)       dispatch_sync这个方法要等到block的执行完之后,才返回

b)      主线程一旦开启,就要先把自己的代码执行完成之后,才去执行加入到主队列中的任务

c)       这样主线程想要执行block,先要下去执行下面的代码,但是因为dispatch_sync这个方法,,如果返回不了,主线程就无法向下再次执行,所以造成了死锁,所以把主线程卡到这里了,造成了死锁

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【Swift 2.1】为 UIView 添加点击.. 下一篇MVC思想架构的简单自定义UITableV..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目