随笔分类 -  多线程

摘要:多线程设计—任务线程确定(检查) 只有确定了有哪些任务线程,哪些共享数据、哪些读写入口,才能设计出好的多线程工作模型; 多线程设计的要素:线程、数据、协作; 阅读全文
posted @ 2020-10-23 16:15 zzfx 阅读(167) 评论(0) 推荐(0) 编辑
摘要:多线程的核心问题是控制共享变量的无序访问(读写) 阅读全文
posted @ 2020-10-19 17:32 zzfx 阅读(150) 评论(0) 推荐(0) 编辑
摘要:锁的本质:操作的序列化、队列化 阅读全文
posted @ 2019-03-07 13:17 zzfx 阅读(330) 评论(0) 推荐(0) 编辑
摘要:竞争与合作 没有先后依赖关系的为竞争 有先后依赖关系的为合作 阅读全文
posted @ 2019-03-06 12:47 zzfx 阅读(137) 评论(0) 推荐(0) 编辑
摘要:线程锁的本质:线程控制、线程状态控制 while if https://www.cnblogs.com/feng9exe/p/8319000.html https://www.cnblogs.com/feng9exe/p/8799312.html https://www.cnblogs.com/fe 阅读全文
posted @ 2019-01-03 16:57 zzfx 阅读(221) 评论(0) 推荐(0) 编辑
摘要:来自:https://github.com/onevcat/Kingfisher 任务计数模式 func testDownloadMultipleImages() { let expectation = self.expectation(description: "wait for all down 阅读全文
posted @ 2018-08-08 10:25 zzfx 阅读(158) 评论(0) 推荐(0) 编辑
摘要:自旋锁的本质是持续占有cpu,直到获取到资源。与其他锁的忙等待的实现机制不同。 昨天有位开发者在 Github 上给我提了一个 issue,里面指出 OSSpinLock 在新版 iOS 中已经不能再保证安全了,并提供了几个相关资料的链接。我仔细查了一下相关资料,确认了这个让人不爽的 bug。 OS 阅读全文
posted @ 2018-03-14 17:48 zzfx 阅读(386) 评论(0) 推荐(0) 编辑
摘要:核心是:将标示对象与锁建立关联。 线程 锁 标识; 异常; NSString *test = @"test"; @try { // Allocates a lock for test and locks it objc_sync_enter(test); test = nil; } @finally 阅读全文
posted @ 2018-03-14 15:16 zzfx 阅读(174) 评论(0) 推荐(0) 编辑
摘要:In computer systems organization or operating systems, "busy waiting" refers to a process that keeps checking something (e.g., an I/O device) to see i 阅读全文
posted @ 2018-02-08 19:11 zzfx 阅读(272) 评论(0) 推荐(0) 编辑
摘要:queue相当于事件处理机制里的事件池;只是任务池; 线程作为事件处理的实施者,由线程池从任务池中获取任务进行调度派发; group相当与工作组,按照任务的相关性对任务进行组织。 阅读全文
posted @ 2018-01-28 00:52 zzfx 阅读(180) 评论(0) 推荐(0) 编辑
摘要:Volatile variables apply another type of memory constraint to individual variables. The compiler often optimizes code by loading the values for variab 阅读全文
posted @ 2018-01-26 18:56 zzfx 阅读(143) 评论(0) 推荐(0) 编辑
摘要:在内核中或者同步变量中维护着一个同步变量和线程的映射关系。 上述结论只是猜测。 阅读全文
posted @ 2018-01-26 17:44 zzfx 阅读(133) 评论(0) 推荐(0) 编辑
摘要:不变量,临界区和判定条件 不变量(Invariant):程序所做的一些假设,特别是指变量之间的关系。如:一个queue,有头节点,和其它数据节点,这些元素之间的连接关系就是不变量。当程序里面不变量遭受破坏时,后果往往是很严重的,轻则数据出错,重则程序直接崩溃。 临界区(Critical Sectio 阅读全文
posted @ 2018-01-26 17:37 zzfx 阅读(402) 评论(0) 推荐(0) 编辑
摘要:使用线程的几种方式 1. 流水线:每个线程反复地在数据系列集上执行同一种操作,并把操作结果传递给下一步骤的其他线程,这就是“流水线”(assembly line)方式; 2 工作组:每个线程都在自己的数据上执行操作。工作组中的线程可能执行同样的操作,也可能执行不同的操作,但是他们一定独立运行; 3 阅读全文
posted @ 2018-01-26 17:35 zzfx 阅读(254) 评论(0) 推荐(0) 编辑
摘要:In concurrent programming, a monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) 阅读全文
posted @ 2018-01-26 17:09 zzfx 阅读(459) 评论(0) 推荐(0) 编辑
摘要:如果互斥锁类型为 PTHREAD_MUTEX_NORMAL,则不提供死锁检测。尝试重新锁定互斥锁会导致死锁。如果某个线程尝试解除锁定的互斥锁不是由该线程锁定或未锁定,则将产生不确定的行为。 如果互斥锁类型为 PTHREAD_MUTEX_ERRORCHECK,则会提供错误检查。如果某个线程尝试重新锁定 阅读全文
posted @ 2018-01-25 23:06 zzfx 阅读(278) 评论(0) 推荐(0) 编辑
摘要:条件变量相当于订阅-发布机制; 或者相当于同步的通知机制; 订阅和发布具有先后顺序;所以需要互斥量来维护顺序。 顺序不对,存在信号丢失问题。 Problem statement[edit] For many applications, mutual exclusion is not enough. 阅读全文
posted @ 2018-01-25 22:17 zzfx 阅读(197) 评论(0) 推荐(0) 编辑
摘要:线程不存在真正的唤醒机制; 所谓的唤醒只是将同步变量置1;在下一个cpu时间片竞争变量,将线程的状态置就绪状态,从而执行; 或者处于自悬状态,有信号释放,立即捕获,从而执行。 阅读全文
posted @ 2018-01-25 22:13 zzfx 阅读(233) 评论(0) 推荐(0) 编辑
摘要:使用条件变量,调用signal/broadcast的时候,无法知道是否已经有线程等在wait上了。因此,一般要先改变条件状态,然后再发送signal/broadcast信号。然后在wait调用线程上先检查条件状态,只有当条件状态为假的时候才进入pthread_cond_wait进行等待,从而防止丢失 阅读全文
posted @ 2018-01-25 20:30 zzfx 阅读(288) 评论(0) 推荐(0) 编辑
摘要:pthreads defines a set of C programming language types, functions and constants. It is implemented with a pthread.h header and a thread library. There 阅读全文
posted @ 2018-01-25 17:13 zzfx 阅读(177) 评论(0) 推荐(0) 编辑