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

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

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

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

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

Chapter 6:Process Synchronization

Chapter 6: Process Synchronization

REVIEW o Semaphores o http://wenku.baidu.com/course/study/77f1dcccda38376ba flfae94#665ea0c7aa00b52acfc7ca94

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

Goals for today o Classic Problems of Synchronization o Monitors

Goals for today  Classic Problems of Synchronization  Monitors

Semaphore o Synchronization tool that does not require busy waiting o Semaphore S-integer variable o Two standard operations modify S:acquire0 and release( Originally called PO and VO o Less complicated o Can only be accessed via two indivisible(atomic)operations acquire(){ while value <=0 ;/no-op value--; release(){ value++;

Semaphore  Synchronization tool that does not require busy waiting  Semaphore S – integer variable  Two standard operations modify S: acquire() and release()  Originally called P() and V()  Less complicated  Can only be accessed via two indivisible (atomic) operations

Semaphore as General Synchronization Tool o Counting semaphore-integer value can range over an unrestricted domain o Binary semaphore-integer value can range only between 0 and 1;can be simpler to implement Also known as mutex locks Semaphore S=new Semaphore(); S.acquire(); /critical section S.release(); /∥remainder section

Semaphore as General Synchronization Tool  Counting semaphore – integer value can range over an unrestricted domain  Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement  Also known as mutex locks

Semaphore Implementation o Must guarantee that no two processes can execute acquire and release on the same semaphore at the same time o Thus,implementation becomes the critical section problem where the wait and signal code are placed in the critical section. Could now have busy waiting in critical section implementation oBut implementation code is short oLittle busy waiting if critical section rarely occupied Note that applications may spend lots of time in critical sections and therefore this is not a good solution

Semaphore Implementation  Must guarantee that no two processes can execute acquire () and release () on the same semaphore at the same time  Thus, implementation becomes the critical section problem where the wait and signal code are placed in the critical section.  Could now have busy waiting in critical section implementation But implementation code is short Little busy waiting if critical section rarely occupied  Note that applications may spend lots of time in critical sections and therefore this is not a good solution

Semaphore Implementation with no Busy waiting o With each semaphore there is an associated waiting queue.Each entry in a waiting queue has two data items: value (of type integer) pointer to next record in the list o Two operations: block-place the process invoking the operation on the appropriate waiting queue. wakeup-remove one of processes in the waiting queue and place it in the ready queue

Semaphore Implementation with no Busy waiting  With each semaphore there is an associated waiting queue. Each entry in a waiting queue has two data items:  value (of type integer)  pointer to next record in the list  Two operations:  block – place the process invoking the operation on the appropriate waiting queue.  wakeup – remove one of processes in the waiting queue and place it in the ready queue

Semaphore Implementation with no Busy waiting (Cont.) o Implementation of acquire(): acquire(){ value--; if (value 0){ add this process to list block; o Implementation of release(: release(){ value++; if (value <=0){ remove a process P from list wakeup(P);

Semaphore Implementation with no Busy waiting (Cont.)  Implementation of acquire():  Implementation of release():

Mutual Exclusion with Semaphores semaphore mutex 1; cobegin /1 pi:while (1){ mutex.acquire(); CSi; mutex.release(); programi; // coend

Mutual Exclusion with Semaphores semaphore mutex = 1; cobegin ... // pi: while (1) { mutex.acquire(); CSi; mutex.release(); programi; } // ... coend;

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