- 3
- 0
- 约1.62万字
- 约 61页
- 2017-07-02 发布于湖北
- 举报
ch07Process Synchronization概要1
Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris 2 Windows 2000 Background Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes. Shared-memory solution to bounded-butter problem (Chapter 4) allows at most n – 1 items in buffer at the same time. A solution, where all N buffers are used is not simple. Suppose that we modify the producer-consumer code by adding a variable counter, initialized to 0 and incremented each time a new item is added to the buffer Bounded-Buffer Shared data #define BUFFER_SIZE 10 typedef struct { . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; int counter = 0; Bounded-Buffer Producer process item nextProduced; while (1) { while (counter == BUFFER_SIZE) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++; } Bounded-Buffer Consumer process item nextConsumed; while (1) { while (counter == 0) ; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--; } Bounded Buffer The statementscounter++;counter--;must be performed atomically. Atomic operation means an operation that completes in its entirety without interruption. Bounded Buffer The statement “count++” may be implemented in machine language as:register1 = counter register1 = register1 + 1counter = register1 The statement “count—” may be implemented as:register2 = counterregister2 = register2 – 1counter = register2 Bounded Buffer If both the producer and consumer attempt to update the buffer concurrently, the assembly language statements may get interleaved. Interleaving depends upon how the producer and consumer processes are scheduled. Bounded Buffer Assume counter is initially 5.
您可能关注的文档
最近下载
- 特定技能2号农业练习题11.docx
- 2026年在带头固本培元、增强党性等五个带头方面对照检查存在的问题、整改措施材料6份文.docx VIP
- 冰川雪山攀登技巧心得分享心得总结.docx VIP
- 小森印刷机s40操作说明.pdf VIP
- 8篇2026年带头固本培元、增强党性(五个带头)方面存在的问题精选.docx VIP
- 翼状胬肉病人护理精品PPT课件.pptx
- 2026年河北省职业病诊断医师资格(尘肺病类)高分突破必练试题库(含答案).docx
- 2024中医临床实践指南穴位埋线减肥.docx VIP
- 人教PEP版五年级下册英语全册教案(单元整体教学设计).docx VIP
- 2025年贵州省公务员考试题及答案解析.docx
原创力文档

文档评论(0)