OS的02进程同步2014-2015-2.pptVIP

  • 6
  • 0
  • 约2.53万字
  • 约 58页
  • 2018-02-18 发布于浙江
  • 举报
OS的02进程同步2014-2015-2

管程定义的是公共数据结构; 进程定义的是私有数据结构PCB 管程把共享变量上的同步操作集中起来 临界区却分散在每个进程中; 管程的设置则是解决共享资源的互斥使用问题 设置进程的目的在于实现系统的并发性; 进程通过调用管程中的过程对共享数据结构实行操作 管程为被动工作方式,进程则为主动工作方式; * 同步和互斥并存 * 基于一个条件协作:不空,不满 * 生产者可以通过过程Put往buffer中增加数据; * * 循环体:至少执行一次,条件为true,退出循环。 问题:共享资源buffer的访问通过共享变量counter来协调,对它的访问也未加控制 *   不是原子操作。 * 4个部分,例子 * 有限等待:退出前,必须释放资源。避免饿死 让权等待:CPU “让权等待”:让何权? 同时满足这4个条件,才是合格的同步机制。 * 但通过这类方法的分析,可以更好地理解并发处理的复杂性 * 不响应中断,不会引发调度 In a uniprocessor system, concurrent processes cannot have overlapped execution; they can only be interleaved. Furthermore, a process will continue to run until it invokes an OS service or until it is interrupted. Therefore, to guarantee mutual exclusion, it is sufficient to prevent a process from being interrupted. This capability can be provided in the form of primitives defined by the OS kernel for disabling and enabling interrupts. Because the critical section cannot be interrupted, mutual exclusion is guaranteed. The price of this approach, however, is high. The efficiency of execution could be noticeably degraded because the processor is limited in its ability to interleave processes. Another problem is that this approach will not work in a multiprocessor architecture. When the computer includes more than one processor, it is possible (and typical) for more than one process to be executing at a time. In this case, disabled interrupts do not guarantee mutual exclusion. * * 信号机制才协调多个进程之间的协作机制。受信号灯启发:进程——汽车 资源——车道(路权)。 英文:旗语。通过信号等控制进程的执行、等待。 它与一般整型量不同, S=0 不可用,红灯 wait(S)和signal(S)是两个原子操作,因此,它们在执行时是不可中断的。亦即,当一个进程在修改某信号量时,没有其他进程可同时对该信号量进行修改。此外,在wait操作中,对S值的测试和做S:=S-1操作时都不可中断。 wait(S):不断检测是否为红灯,一旦变可用,进入,关门。 signal: 释放资源 * Busy waiting means that a process is waiting for a condition to be satisfied in a tight loop without relinquishing the processor. Alternatively, a process could wait by relinquishing the processor, and block on a condition and wait to be awakened at some appropriate time in the future. Busy waiting can be avoided but incurs the overhead

文档评论(0)

1亿VIP精品文档

相关文档