1. 1、本文档共88页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
多核编程C

Mutual Exclusion Critical Region ? Portion of code that accesses (reads writes) shared variables Mutual Exclusion ? Program logic to enforce single thread access to critical region ? Enables correct programming structures for avoiding race conditions Example: Safe Deposit box ? Attendants ensure mutual exclusion Synchronization Synchronization objects used to enforce mutual exclusion ? Lock, semaphore, critical section, event, condition variable,atomic ? One thread “holds” sync. object; other threads must wait ? When done, holding thread releases object; some waiting thread given object Example: Library book ? One student has borrowed book out ? Others must wait for book to return Barrier Synchronization Threads pause at execution point ? Threads waiting are idle; overhead When all threads arrive, all are released Example: Race starting line Deadlock Threads wait for some event or condition that will never happen Example: ? Traffic jam at intersection ? Cars unable to turn or back up What is Livelock? ? Threads change state in response to each other Example: ? Robin Hood and Little John on log bridge 死锁其他示例 进程死锁的例子 竞争外部设备 竞争辅存空间 死锁定义及性质 死锁定义 在一个进程集合中,若每个进程都在等待某些事件(指:释放资源)的发生,而这些事件又必须由这个进程集合中的某些进程来产生,就称该进程集合处于死锁状态。 死锁定义及性质 出现死锁的系统必须同时满足下列四个必要条件 互斥:必须存在需要互斥使用的资源 占有等待:一定有占有资源而又等待其它资源的进程 非剥夺:系统中进程占有的资源未主动释放时不可以剥夺 循环等待:进程集合{P0, P1, ……, Pn},Pi等待Pi+1,Pn等待P0 破坏互斥占用条件 让资源共享使用(但有些资源必须互斥) 破坏占有等待条件 将进程所要资源一次性分给进程,要么没分到一个资源,要么全部满足(适合廉价资源的分配,如外存空间分配) 进程在下一轮申请资源时,释放所占的所有资源 (用完一个再用下一个) 死锁的防止 破坏循环等待条件 采用资源顺序分配方法:给每类资源编号,进程只能按序号由小到大的顺序申请资源,若不满足则拒绝分配。 反证:若出现循环等待,则必会有小序号资源序号大序号资源序号。 Lab 4 Intel ??Thread Checker工具的使用 实验一 找出程序中潜在的数据竞争 \code\Thread Checker\potential_serial\ ; 实验二 死锁问题的解决 \code\Thread Checker\potential_win\ ; 实验三 线程安全性测试问题 \code\Thread Checker\Deadlock\Thread Safe Libraries ; 多核软件开发工具 Intel ? C++ Compiler Intel ? VTune 性能分析和调整工具 IPP 和 MKL OpenMP Intel ??Thread Checker Intel ??

文档评论(0)

qwd513620855 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档