CHAPTER 5 Concurrency: Mutual Exclusion and Synchronization (并发性:互斥和同步)
Concurrency (并发性) Communication among processes Sharing of and competing(竞争)or resources Synchronization of the activities of multiple processes Allocation of processor time to processer
Concurrency Multiple applications Multiprogramming Structured application Application can be a set of concurrent processes Operating-system structure Operating system is a set of processes or th reads
5.1 PRINCIPLES OF NCURRENCY (并发的原理) Difficulties with Concurrency 1. Sharing global resources 2. Management of allocation of resources 3. It become very difficult to locate a Programming errors
A Simple example procedure echo; Var out in: character; begin input (in, keyboard) out: s in outputout, display)i end
A Simple example Process p1 Process p2 Input(in, keyboard) Input(in, keyboard) Out: in ou七:=in Output(out, display) Output(out, display)
Operating System Concerns (操作系统关注的问题) Keep track of active processes: PCB Allocate and deallocate resources Processor time: scheduling Memory virtual memory Files 1o devices Protect data and resources Result of process must be independent of the speed of execution of other concurrent processes (应保证进程执行的结果与速度无关)
Process Interaction Processes unaware of each other Competition Mutual exclusion, Deadlock, starvation Processes indirectly aware of each other Cooperation by sharing Mutual exclusion Deadlock. Starvation. Data coherence (一致性) Process directly aware of each other Cooperation by communication Deadlock. Starvation
一致性)
表5.1进程的交互 知道程度 关系 个进程对其他进程的影响潜在的控制问题 进程之间不知道对竞争 个进程的结果与其它进互斥 方 程的活动无关 死锁(可复用的资 (进程间无工作联 2进程的分时可能会受到影源) 系) 响 饿死 进程间接知道对方通过共 个进程的结果可能依赖互斥 (如共享对象) 享合作于从其他进程获得的信息 死锁(可复用的资 2进程的分时可能会受到影源) 响 饿死 数据一致性 进程直接知道对方通过通1.一个进程的结果可能依赖死锁(可消费的资 (它们有可用的通信合作于从其他进程获得的信息 源 信原语) 2进程的分时可能会受到影饿死
表5.1进程的交互 知道程度 关系 一个进程对其他进程的影响 潜在的控制问题 进程之间不知道对 方 (进程间无工作联 系) 竞争 1 一个进程的结果与其它进 程的活动无关 2 进程的分时可能会受到影 响 互斥 死锁(可复用的资 源) 饿死 进程间接知道对方 (如共享对象) 通过共 享合作 1. 一个进程的结果可能依赖 于从其他进程获得的信息 2. 进程的分时可能会受到影 响 互斥 死锁(可复用的资 源) 饿死 数据一致性 进程直接知道对方 (它们有可用的通 信原语) 通过通 信合作 1. 一个进程的结果可能依赖 于从其他进程获得的信息 2. 进程的分时可能会受到影 响 死锁(可消费的资 源) 饿死
Competition Among processes for resources Mutual exclusion(互斥) Critical sections(临界区) Only one program at a time is allowed in its critical section(一次仅允许一个进程在临界区) Example only one process at a time is allowed to send command to the printer (critical resource (例如一次仅允许一个进程发打印命令) Deadlock(死锁) · Starvation
critical resource) (例如一次仅允许一个进程发打印命令)