Operating System Process Management - 4 Monday, August 11, 2008.

Slides:



Advertisements
Similar presentations
新目标初中英语 七年级下册. Unit 8 I’d like some noodles. Section B Period Two.
Advertisements

allow v. wrong adj. What’s wrong? midnight n. look through guess v. deal n. big deal work out 允许;准许 有毛病;错误的 哪儿不舒服? 午夜;子夜 快速查看;浏览 猜测;估计 协议;交易 重要的事.
Multicore Programming Final Review. Outline Intro to Parallelism and Concurrency Parallel Programming – Algorithms and Analysis Concurrent Programming.
作者 : 陳鍾誠 單位 : 金門技術學院資管系 URL : 日期 : 2016/7/21 行程的同步 註:本章學術性較重,但考試常考。
1 I/O 设备访问方式和类型. 2 Overview n The two main jobs of a computer: l I/O (Input/Output) l processing n The control of devices connneted to the computer is.
8 Click.
Unit 9 Have you ever been to an amusement park? Section A.
2007年8月龙星课程 周源源老师课程体会 包云岗 中科院计算所
Foundations of Computer Science
专题八 书面表达.
Chapter 17 數位革命與全球電子市場 Global Marketing Warren J. Keegan Mark C. Green.
第二章 进程的描述与控制管理.
作業系統 第六章 同步與死結.
Chapter 7: Process Synchronization 进程同步
第6章 死結(Deadlock).
PURSUING EXCELLENCE / TOWARD SUCCESS WUCHANG UNIVERSITY OF TECHNOLOGY
Chapter 6 同步 (Synchronization)
What were you doing when the UFO arrived?
Operating System CPU Scheduing - 2 Monday, August 11, 2008.
Operating System CPU Scheduing - 3 Monday, August 11, 2008.
Unit 4 I used to be afraid of the dark.
Unit 2 What should I do?.
Module 6 Animals in danger
操作系统 (并发进程) 徐锋 南京大学计算机科学与技术系 2018年9月18日3时52分.
Operating System Concepts 作業系統原理 Chapter 3 行程觀念 (Process Concept)
中国科学技术大学计算机系 陈香兰 2013Fall 第五讲 进程同步和通信(part II) 中国科学技术大学计算机系 陈香兰 2013Fall.
第六章 应用程序结构.
Applied Operating System Concepts
Deadlocks P0 P1 Example System has 2 tape drives.
英语教学课件系列 八年级(上) it! for Go.
第 17 章 數位革命與 全球電子市場 © 2005 Prentice Hall.
经典同步问题.
作業系統 第六章 同步與死結.
Chapter 3 行程觀念 (Process Concept)
创建型设计模式.
ICT RTOS Research Group 胡伟平,王剑
Area of interaction focus
第三章 进程互斥与同步.
第三章 进程互斥与同步 进程通信 Communication.
SAP 架構及基本操作 SAP前端軟體安裝與登入 Logical View of the SAP System SAP登入 IDES
Chapter 4 多執行緒 (Multi Thread)
Lesson 17 Renting an Apartment 租房子
操作系统原理 Operating System Principles
李元金 计算机与信息工程学院 第 4 讲 进程管理(2) 李元金 计算机与信息工程学院 1/
Unit 4.
第3章 認識處理元.
第十五课:在医院看病.
Review Final Chinese 2-Chapter 6~10-1
解读设题意图,探究阅读策略 年高考试卷题型(阅读理解)分析及对策
第2章 进程管理 2.1 进程概念 2.2 线程 2.3 进程管理 2.4 进程间通信 2.5 经典进程同步问题 2.6 管程
第2章 进程和线程 内容提要: 2.1 进 程 概 念 2.2 进程的状态和组成 2.3 进 程 管 理 2.4 线 程.
Unit 1 How can we become good learners?
SAP R/3架構及前端軟體安裝 Logical View of the R/3 System SAP Frontend 6.2安裝
Operation System(OS).
虚 拟 仪 器 virtual instrument
中国科学技术大学计算机系 陈香兰 Fall 2013 第三讲 线程 中国科学技术大学计算机系 陈香兰 Fall 2013.
第7章 進階的同步 觀念與實務.
高考应试作文写作训练 5. 正反观点对比.
计算机问题求解 – 论题1-5 - 数据与数据结构 2018年10月16日.
CHAPTER 6 Concurrency:deadlock And Starvation
SAP 架構及基本操作 SAP前端軟體安裝與登入 Logical View of the SAP System SAP登入 IDES
8 Click.
M; Well, let me check again with Jane
8Click.
Operating System Software School of SCU
8 Click.
Race Conditions and Semaphore
SAP 架構及前端軟體安裝 Logical View of the SAP System SAP Frontend 7.1安裝 SAP登入
Hospitality English 酒店商务英语 讲师:罗云利 工商与公共管理学院.
中正大學,資工系,作業系統實驗室 陽春副教授 羅習五
Presentation transcript:

Operating System Process Management - 4 Monday, August 11, 2008

Roadmap Process Concepts Process Scheduling Interprocess Communication Mutex and Synchronization Classical IPC Problems Threads 8/11/2008 6:14 PM bettynj@gmail.com

Classical Problems of IPC Bounded-Buffer Problem Readers and Writers Problem Dining-Philosophers Problem 8/11/2008 6:14 PM bettynj@gmail.com

Readers-Writers Problem This is the same as the Producer / Consumer problem except - we now can have many concurrent readers and one exclusive writer. Locks: shared (for the readers) exclusive (for the writer). Two possible ( contradictory ) guidelines can be used No reader is kept waiting unless a writer holds the lock (the readers have precedence). If a writer is waiting for access, no new reader gains access (writer has precedence). 一个数据对象(如文件或记录)可以为多个并发进程所共享。其中有的进程只需要读共享对象的内容,而其他进程可能要更新(即读和写)共享对象。为了区分这两种类型的进程,将只对读感兴趣的进程称为读者;而其他得则称为写者。 显然,如果两个读者同时访问共享数据对象,那么不会产生什么不利的结果。然而,如果一个作者和其他一些进程(读者或作者)同时访问共享对象,很可能产生混乱。 8/11/2008 6:14 PM bettynj@gmail.com

Readers-Writers Problem do { wait( wrt ); /*writing is performed*/ signal( wrt ); } while(TRUE); BINARY_SEMAPHORE wrt = 1; BINARY_SEMAPHORE mutex = 1; int readcount = 0; Reader: do { wait( mutex ); /* Allow 1 reader in entry*/ readcount = readcount + 1; if(readcount == 1) then wait(wrt ); /* 1st reader locks writer */ signal( mutex );   /* reading is performed */   wait( mutex ); readcount = readcount - 1; if(readcount == 0) then signal(wrt ); /*last reader frees writer */ } while(TRUE); 为了确保不会产生混乱,要求作者对共享对象有完全的访问。 信号量wrt为读者和写者进程所共用,供写者作为互斥信号量使用。 信号量mutex用于确保在更新变量readcount时的互斥。 变量readcount用来跟踪有多少进程正在读对象。 8/11/2008 6:14 PM bettynj@gmail.com

Dining-Philosophers Problem Description: 5 philosophers with 5 chopsticks sit around a circular table. They each want to eat at random times and must pick up the chopsticks on their right and on their left.  Clearly deadlock is rampant ( and starvation possible.) 假设有5个哲学家,他们花费一生中的时光思考和吃饭。这些哲学家共用一个圆桌,每个哲学家都有一把椅子。在桌子中间是一碗面,在桌子上放着5只筷子。当一个哲学家思考时,他与其他同事不交互。时而,哲学家会感到饥饿,并试图拿起与他相近的两只筷子(他与邻近左、右两人之间的筷子)。一个哲学家一次只能拿起一支筷子。显然,他不能从其他哲学家手里拿走筷子。当一个饥饿的哲学家同时有量只筷子时,他就能不用释放他的筷子而自己吃了。当吃完后,他会放下两只筷子,并再次开始思考。 解决方法:每只筷子都用一个信号量来表示。一个哲学家对信号量执行wait操作试图夺取相应的筷子;他会通过对适当信号量执行signal操作以释放相应的筷子。 8/11/2008 6:14 PM bettynj@gmail.com

A nonsolution to the dining philosophers problem 8/11/2008 6:14 PM bettynj@gmail.com

Dining-Philosophers Problem Several solutions are possible: Allow only 4 philosophers to be hungry at a time. Allow pickup only if both chopsticks are available. ( Done in critical section ) Odd # philosopher always picks up left chopstick 1st, even # philosopher always picks up right chopstick 1st. 8/11/2008 6:14 PM bettynj@gmail.com

Solution - 2 monitor dp { enum {thinking, hungry, eating} state[5]; condition self[5]; } Solution - 2 void putdown(int i) { state[i] = thinking;// test left & right neighbors test((i+4) % 5); test((i+1) % 5); } void philosopher(int i) { while(true){ thinking(); pickup(i); eating(); putdown(i); } void pickup(int i) { state[i] = hungry; test[i]; if (state[i] != eating) self[i].wait(); } void test(int i) { if ( (state[(i + 4) % 5] != eating) && (state[i] == hungry) &&(state[(i + 1) % 5] != eating)) { state[i] = eating; self[i].signal(); } initializationCode() { for ( int i = 0; i < 5; i++ )state[i] = thinking; } 8/11/2008 6:14 PM bettynj@gmail.com

Windows 2000 Synchronization Kernel threads synchronization Uses interrupt masks to protect access to global resources on uniprocessor systems. Uses spinlocks on multiprocessor systems. Other threads synchronization Also provides dispatcher objects used as sychronization mechanisms. Dispatcher objects include timer objects, event objects, semaphore objects, mutex objects, and thread objects. 8/11/2008 6:14 PM bettynj@gmail.com

Keystone Different kinds of tools for sychronization , including semaphores, critical regions and monitors The bounded-buffer problem and solution The readers-writers problem and solution The dining-philosophers problem and solution 8/11/2008 6:14 PM bettynj@gmail.com

Homework The Sleeping-Barber Problem: A barbershop consists of a waiting room with n chairs and the barber room containing the barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop. If the barber is busy but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber. Write a program to coordinate the barber and the customers. 8/11/2008 6:14 PM bettynj@gmail.com

Classical IPC Problems Operating System Classical IPC Problems Monday, August 11, 2008