中国高校课件下载中心 》 教学资源 》 大学文库

上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Process Synchronization_Lec12

文档信息
资源类别:文库
文档格式:PDF
文档页数:25
文件大小:398.81KB
团购合买:点击进入团购
内容简介
上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Process Synchronization_Lec12
刷新页面文档预览

OPERATING SYSTEMS 1 龚玲 lgong@sjtu.edu.cn

OPERATING SYSTEMS 龚玲 lgong@sjtu.edu.cn 1

Chapter 6:Process Synchronization

Chapter 6: Process Synchronization

REVIEW o Race Condition ohttp://wenku.baidu.com/course/study/77f1dcccda38376ba flfae94#665ea0c7aa00b52acfc7ca94

REVIEW  Race Condition  http://wenku.baidu.com/course/study/77f1dcccda38376ba f1fae94#665ea0c7aa00b52acfc7ca94

Goals for today o Background oThe Critical-Section Problem o Peterson's Solution o Synchronization Hardware

Goals for today  Background  The Critical-Section Problem  Peterson’s Solution  Synchronization Hardware

Background-Race Conditions o Two processes want to access shared memory at the same time. Spooler directory 4 abc out =4 5 Process A prog.c 6 prog.n in =7 Process B 5

Background-Race Conditions  Two processes want to access shared memory at the same time. 5

Process Interactions o Competition:The Critical Problem x=0; cobegin p1:… x=x+1 1 p2:… x=x+1: coend o x should be 2 after both processes execute 6

Process Interactions  Competition: The Critical Problem x = 0; cobegin p1: … x = x + 1; … // p2: … x = x + 1; … coend  x should be 2 after both processes execute 6

The Critical Problem o Interleaved execution (due to parallel processing or context switching): p1:R1= X p2: R1=R1+1; R2 x; x=R1; R2=R2 +1 x=R2; ox has only been incremented once The first update (=R1)is lost

The Critical Problem  Interleaved execution (due to parallel processing or context switching): p1: R1 = x; p2: … R1 = R1 + 1; R2 = x; x = R1 ; R2 = R2 + 1; … x = R2;  x has only been incremented once The first update (x=R1) is lost. 7

Race condition oSeveral processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place

Race condition Several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place

Background o Concurrent access to shared data may result in data inconsistency o Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Suppose that we wanted to provide a solution to the consumer-producer problem that fills all the buffers.We can do so by having an integer count that keeps track of the number of full buffers. Initially,count is set to 0.It is incremented by the producer after it produces a new buffer and is decremented by the consumer after it consumes a buffer

Background  Concurrent access to shared data may result in data inconsistency  Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes  Suppose that we wanted to provide a solution to the consumer-producer problem that fills all the buffers. We can do so by having an integer count that keeps track of the number of full buffers. Initially, count is set to 0. It is incremented by the producer after it produces a new buffer and is decremented by the consumer after it consumes a buffer

Producer while (count ==BUFFER_SIZE) ;/do nothing /add an item to the buffer ++count; buffer[in]item; in (in +1)%BUFFER _SIZE;

Producer

共25页,试读已结束,阅读完整版请下载
刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档