ch07_Process Synchronization.ppt


文档分类:IT计算机 | 页数:约50页 举报非法文档有奖
1/50
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/50
文档列表 文档介绍
Chap 7 Process Synchronization 进程同步
编写:李培峰
Applied Operating System Concepts
内容
Background(背景)
The Critical-Section Problem (临界区问题)
Semaphores (信号量)
Classical Problems of Synchronization(经典同步问题)
Monitors (管程)
Java Synchronization (Java中的同步机制)
Synchronization in Solaris 2 (Solaris 2的同步机制)
Synchronization in Windows NT (Windows NT的同步机制)
Summary(总结)
Applied Operating System Concepts
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) has a race condition on the class data count ([第4章中]解决有界缓冲区问题的共享内存方法在类数据count 上将一起竞争条件)
Applied Operating System Concepts
Bounded Buffer :enter() Method 有界缓冲: enter()方法
// producer calls this method
public void enter(Object item) {
while (count == BUFFER_SIZE)
; // do nothing
// add an item to the buffer
++count;
buffer[in] = item;
in = (in + 1) % BUFFER_SIZE;
}
Applied Operating System Concepts
Bounded Buffer:remove() Method 有界缓冲: remove ()方法
// consumer calls this method
public Object remove() {
Object item;
while (count == 0)
; // do nothing
// remove an item from the buffer
--count;
item = buffer[out];
out = (out + 1) % BUFFER_SIZE;
return item;
}
Applied Operating System Concepts
Machine Language of ++count and –count ++count 和–count的机器语言
++count:
R1=count; 1
R1=R1+1; 2
count=R1; 3
--count:
R2=count; 4
R2=R2-1; 5
count=R2; 6
Count初值为4,并发执行remove()和enter()进程
执行次序
结果
是否正确
123456
4

142536
3

145263
5

Applied Operating System Concepts
Critical Resource & Critical-Section 临界资源和临界区
critical resource(临界资源)
系统中某些资源一次只允许一个进程使用,称这样的资源为临界资源或互斥资源或共享变量。
Critical-Section(临界区)
涉及到临界资源的代码段叫临界区。
Applied Operating System Concepts
Solution to Critical-Section Problem 解决临界区问题
1. Mutual Exclusion. If process Pi is executing in its critical section,

ch07_Process Synchronization 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数50
  • 收藏数0 收藏
  • 顶次数0
  • 上传人中国课件站
  • 文件大小0 KB
  • 时间2011-09-06