- 3
- 0
- 约8.86千字
- 约 29页
- 2018-03-29 发布于广东
- 举报
四川丹甫制冷压缩机股份有限公司招.90
Outline for Today Objective: To continue talking about the critical section problem and get more practice thinking about possible interleavings. Start talking about synchronization primitives. Introduce other “classic” concurrency problems Administrative details: Look on the web for TAs’ office hours or check newsgroup for UTAs’ office hours for assignment 1. On collecting problem sets… Semaphores Well-known synchronization abstraction Defined as a non-negative integer with two atomic operations P(s) - [wait until s 0; s--] V(s) - [s++] The atomicity and the waiting can be implemented by either busywaiting or blocking solutions. Semaphore Usage Binary semaphores can provide mutual exclusion (solution of critical section problem) Counting semaphores can represent a resource with multiple instances (e.g. solving producer/consumer problem) Signaling events (persistent events that stay relevant even if nobody listening right now) Producer / Consumer Producer: while(whatever) { locally generate item fill empty buffer with item } Consumer: while(whatever) { get item from full buffer use item } Producer / Consumer Producer: while(whatever) { locally generate item fill empty buffer with item } Consumer: while(whatever) { get item from full buffer use item } Tweedledum and Tweedledee Separate threads executing their respective procedures. The idea to cause them to forever take turns exchanging insults through the shared variable X in strict alternation. The Sleep() and Wakeup() routines operate as follows: Sleep blocks the calling thread, Wakeup unblocks a specific thread if that thread is blocked, otherwise its behavior is unpredictable The code shown above exhibits a well-known synchronization flaw. Outline a scenario in which this code would fail, and the outcome of that scenario void Tweedledum() { while(1) { Sleep(); x = Quarrel(x); Wakeup(Tweedledee); } } void Tw
您可能关注的文档
最近下载
- 人教(统编)版高中语文必修上册 详解答案.docx VIP
- 高一第二学期语文期末试卷.docx VIP
- 年产1.5万吨竹纤维餐具热压成型项目可行性研究报告.docx
- 《铁路货物站台面及堆货场铺面》壹站(02)8029.pdf VIP
- 公司2025年度民主生活会领导班子对照检查材料(五个带头) (3).docx VIP
- 译林版高中英语选修一单词默写表.pdf VIP
- 上海市高考语文复习:文言文精短翻译练习100篇(答案).pdf VIP
- CSCO非小细胞肺癌诊疗指南2025.docx VIP
- 2025年第二学期高一语文期末试卷及答案.docx VIP
- 高三英语一轮语法复习《非谓语动词》精品课件.ppt VIP
原创力文档

文档评论(0)