Processor Management (Thread and Deadlock)

Slides:



Advertisements
งานนำเสนอที่คล้ายกัน
Strength of Materials I EGCE201 กำลังวัสดุ 1
Advertisements

E-COMMERCE WEBSITE Smartzap Co., Ltd.. Company Profile บริษัท สมาร์ทแซป จำกัด ก่อตั้งเมื่อปี 2543 (13 ปี ) ในช่วงยุค Internet เพิ่ง เริ่มต้น เป็นบริษัทที่ดำเนินงานทางด้าน.
John Rawls  John Rawls is the most famous American social contract theorist argued that “Justice is fairness” He Thought human natural have a appropriate.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Java Programming Language.
การแนะนำสถานที่ ชั้นมัธยมศึกษาปีที่ 6/4 1. นางสาวดลยา พลอาวุธ เลขที่ นางสาวปภัสสร สายสมบัติ เลขที่ นางสาวศิริพร ประสมศรี เลขที่ 36.
Set is a basic term in Mathematics. There is no precise definition for term “set”, But roughly speaking, a set is a collection of objects, Things or symbols,
IT685 หัวข้อพิเศษในเทคโนโลยีสารสนเทศ 2 IT&Cloud/ Infrastructure
INC 551 Artificial Intelligence Lecture 2. Review Environment Action Sense, Perceive Make Decision Agent World Model Deliberative Agent.
ขั้นตอนวิธีและเครื่องมือในการพัฒนาโปรแกรม (ต่อ)
จำนวน สถานะ NUMBER OF STATES. ประเด็นที่ สนใจ The number of distinct states the finite state machine needs in order to recognize a language is related.
INTELLECTUAL CAPITAL : IC Group 3: Tipada Subhasean Nongluk Charoeschai Nerisa Wangkarat
Chapter 9 : Designing Approach
Graphical User Interface charturong.ee.engr.tu.ac.th/CN208
Braille OCR Mobile Application
รู้จักกับเทคโนโลยี RFID เบื้องต้น
Emergency Response System for Elderly and PWDs: Design & Development
Concurrency Control Recovery Management
COMMUNICATION IN BUSINESS
VARIABLES, EXPRESSION and STATEMENTS. Values and Data Types Value เป็นสิ่งพื้นฐาน มีลักษณะเป็น ตัวอักษร หรือ ตัวเลข อาทิ 2+2 หรือ “Hello world” Value.
อาจารย์ มธ. อธิบายการใช้ โมเดลของ
ระบบการจัดเก็บในคลังสินค้า
: Chapter 1: Introduction 1 Montri Karnjanadecha ac.th/~montri Image Processing.
Color Standards A pixel color is represented as a point in 3-D space. Axis may be labeled as independent colors such as R, G, B or may use other independent.
ออโตมาตาจำกัด FINITE AUTOMATA
REGULAR EXPRESSION การบรรยายแบบสม่ำเสมอ
บทที่ 12 Virtual Private Networks
Helping you make better treatment decisions for your patients.
Positive Accounting Theory
Chapter 19 Network Layer: Logical Addressing
Inductive, Deductive Reasoning ผศ.( พิเศษ ) น. พ. นภดล สุชาติ พ. บ. M.P.H.
Course Software Engineering SE Overview and Introduction.
Chapter 12 Riveted, Bolted & Welded Connections
Problem with Subjunctive Verbs Some verbs and noun require a subjunctive. A subjunctive is a change in the usual form of the verb. It is often a verb word.
คำสั่ง READ รูปแบบ READ file-name RECORD [INTO identifier] [AT END imperative- statement] ตัวอย่าง READ STUDENT-FILE AT END GO TO END-PROCESS. READ CUSTOMER-FILE.
การออกแบบและพัฒนาซอฟต์แวร์ บทที่ 7 การทดสอบโปรแกรม
MAT 231: คณิตศาสตร์ไม่ต่อเนื่อง (3) Function Growth & Time-Complexity
8/3/2014The Realities of software Testing1 Software testing Realities What is the realities of software testing Why does the software testing not complete.
Merchant Marine Training Centre วิชาการเป็นเลิศ เชิดชู คุณธรรม ผู้นำ.
บทที่ 2 งบการเงินพื้นฐาน BASIC FINANCIAL STATEMENTS 2.
Kampol chanchoengpan it สถาปัตยกรรมคอมพิวเตอร์ Arithmetic and Logic Unit 1.
Sawit Soothipunt Senior Product Manager Microsoft (Thailand) Limited.
Algorithm Efficiency There are often many approaches (algorithms) to solve a problem. How do we choose between them? At the heart of computer program.
วิธีการ Auto ship.
Introduction to Earned Value Analysis.
Writing a research. Why Research?  To find whether the messages and the materials are appropriate to the target group  To modify the messages and the.
8 Identifying Market Segments and Targets
Thread Thread ส่วนของ process ที่ให้ CPU ประมวลผล.
ผัก. หน่อไม้ ฝรั่ง กะหล่ำ ปลี แค รอท กะหล่ำ ดอก.
ผู้ให้สัมมนา นายธเนศ เกษศิลป์ รหัส ภาควิชานิติวิทยาศาสตร์
การสร้าง WebPage ด้วย Java Script Wachirawut Thamviset.
เอกสารเรียนวันที่ 27 มกราคม 2555
เอกสารเรียนวันที่ 7 กันยายน 2555
Chapter 3 Simple Supervised learning
Chapter 1/1 Arrays. Introduction Data structures are classified as either linear or nonlinear Linear structures: elements form a sequence or a linear.
21 August ดรุณี ศมาวรรตกุล 1 2. ADT List - Unsorted list ADT - list implementation - Sorted List - Circular list - Doubly linked list.
An Online Computer Assisted Instruction Development of Electronics Devices Subject for Learning Effectiveness Testing By Assoc.Prof. Suwanna Sombunsukho.
Introduction of DREAM สุวรรณา ประณีตวตกุล คณะเศรษฐศาสตร์ มหาวิทยาลัยเกษตรศาสตร์
Bitcoin Mining. Hello, I’m Pawaris and I love Bitcoin.
 Mr.Nitirat Tanthavech.  HTML forms are used to pass data to a server.  A form can contain input elements like text fields, checkboxes, radio-buttons,
DEADLOCKS Advanced Operating System Operating System Technology
The management of change Changes in work patterns and jobs
Soroptimist International
<insert problem title>
Forces and Laws of Motion
Workday Merit Process - Approvers
Extreme Programming Explained: Embrace Change
STRATEGIES FOR SUCCESS
Year 9 Term 1 Foundation (Unit 1) INTEGERS, ROUNDING AND PLACE VALUE
CPU and I/O bursts.
Deadlocks pp. 309.
ใบสำเนางานนำเสนอ:

Processor Management (Thread and Deadlock) บทที่ 5 Processor Management (Thread and Deadlock)

ประเด็นที่ต้องพิจารณา ถ้าโปรแกรมทำงานทีละคำสั่ง ตามลำดับ เมื่อสั่งพิมพ์ออก spooler ก็ไม่สามารถป้อนเนื้อหาใหม่ ไม่สามารถ save งาน ไม่สามารถทำอย่างอื่นได้ ต้องหยุดรอจนกว่าจะพิมพ์เสร็จ งานอื่นเช่นการสั่ง save หรือป้อนเนื้อหาใหม่ น่าจะทำไปพร้อมกันได้ ไม่จำเป็นจะต้องรอ ขณะรอ ถ้าไม่มีงานอื่น CPU ก็ว่าง สูญเสียไปโดยเปล่าประโยชน์ น่าที่โปรแกรมเดียว ควรจะสามารถทำงานหลายๆงานไปพร้อมกันได้ เกิดแนวคิดที่เรียกว่า thread ในแต่ละ process อาจมี thread เดียวหรือหลาย thread ก็ได้ Context switching ระหว่าง thread ใน process เดียวกัน จะเร็วกว่า context switching ระหว่าง process เพราะ thread ใช้ข้อมูลร่วมกันเป็นส่วนใหญ่

Thread Usage (1) Figure 2-7. A word processor with three threads. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Thread Usage (2) Figure 2-8. A multithreaded Web server. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Thread Usage (3) Figure 2-9. A rough outline of the code for Fig. 2-8. (a) Dispatcher thread. (b) Worker thread. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Thread Usage (4) Figure 2-10. Three ways to construct a server. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Thread Scheduling (1) Figure 2-43. (a) Possible scheduling of user-level threads with a 50-msec process quantum and threads that run 5 msec per CPU burst. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Thread Scheduling (2) Figure 2-43. (b) Possible scheduling of kernel-level threads with the same characteristics as (a). Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

กิจกรรม ให้นักศึกษาทั้ง 6 กลุ่ม แบ่งออกเป็น 3 กลุ่มใหญ่ โดยให้กลุ่มที่นั่งติดกัน 2 กลุ่มรวมเป็นกลุ่มใหญ่กลุ่มเดียว ทำกิจกรรมตามที่อาจารย์สั่งในห้อง สรุปผลกิจกรรม

Four Conditions for Deadlock Deadlock preceded by simultaneous occurrence of four conditions that operating system could have recognized: Mutual exclusion Resource holding No preemption Circular wait Understanding Operating Systems

Mutual exclusion -- the act of allowing only one process to have access to a dedicated resource. Resource holding -- the act of holding a resource and not releasing it; waiting for the other job to retreat. No preemption -- the lack of temporary reallocation of resources; once a job gets a resource it can hold on to it for as long as it needs. Circular wait -- each process involved in impasse is waiting for another to voluntarily release the resource so that at least one will be able to continue. Understanding Operating Systems

A Lack of Process Synchronization Causes Deadlock or Starvation Deadlock (“deadly embrace”) -- a system-wide tangle of resource requests that begins when 2+ jobs are put on hold. Each job is waiting for a vital resource to become available. Needed resources are held by other jobs also waiting to run but can’t because they’re waiting for other unavailable resources. The jobs come to a standstill. The deadlock is complete if remainder of system comes to a standstill as well. Resolved via external intervention. Understanding Operating Systems

Seven Cases of Deadlocks 1. Deadlocks on file requests 2. Deadlocks in databases 3. Deadlocks in dedicated device allocation 4. Deadlocks in multiple device allocation 5. Deadlocks in spooling 6. Deadlocks in disk sharing 7. Deadlocks in a network Understanding Operating Systems

Case 1 : Deadlocks on File Requests If jobs can request and hold files for duration of their execution, deadlock can occur. Any other programs that require F1 or F2 are put on hold as long as this situation continues. Deadlock remains until a programs is withdrawn or forcibly removed and its file is released. Understanding Operating Systems

Case 2 : Deadlocks in Databases 1. P1 accesses R1 and locks it. 2. P2 accesses R2 and locks it. 3. P1 requests R2, which is locked by P2. 4. P2 requests R1, which is locked by P1. Deadlock can occur if 2 processes access & lock records in database. 3 different levels of locking : entire database for duration of request a subsection of the database individual record until process is completed. If don’t use locks, can lead to a race condition. Understanding Operating Systems

Case 3: Deadlocks in Dedicated Device Allocation 1. P1 requests tape drive 1 and gets it. 2. P2 requests tape drive 2 and gets it. 3. P1 requests tape drive 2 but is blocked. 4. P2 requests tape drive 1 but is blocked. Deadlock can occur when there is a limited number of dedicated devices. E.g., printers, plotters or tape drives. Understanding Operating Systems

Case 4 : Deadlocks in Multiple Device Allocation Deadlocks can happen when several processes request, and hold on to, dedicated devices while other processes act in a similar manner. Understanding Operating Systems

Case 5 : Deadlocks in Spooling Most systems have transformed dedicated devices such as a printer into a sharable device by installing a high-speed device, a disk, between it and the CPU. Disk accepts output from several users and acts as a temporary storage area for all output until printer is ready to accept it (spooling). If printer needs all of a job's output before it will begin printing, but spooling system fills available disk space with only partially completed output, then a deadlock can occur. Understanding Operating Systems

Case 6 : Deadlocks in Disk Sharing P1 Read records at cylinder 20 P2 Write to file at cylinder 310 I/O Channel Disk control unit Disks are designed to be shared, so it’s not uncommon for 2 processes access different areas of same disk. Without controls to regulate use of disk drive, competing processes could send conflicting commands and deadlock the system. Understanding Operating Systems

Case 7: Deadlocks in a Network A network that’s congested (or filled large % of its I/O buffer space) can become deadlocked if it doesn’t have protocols to control flow of messages through network. Understanding Operating Systems

Modeling Deadlocks Using Directed Graphs (Holt, 1972) Processes represented by circles. Resources represented by squares. Solid line from a resource to a process means that process is holding that resource. Solid line from a process to a resource means that process is waiting for that resource. Direction of arrow indicates flow. If there’s a cycle in the graph then there’s a deadlock involving the processes and the resources in the cycle. Understanding Operating Systems

Directed Graph Examples Figure 5.7 (a) R1 P1 Figure 5.7 (c) Figure 5.7 (b) Understanding Operating Systems

R1 P1 R3 R2 P3 P2 R1 P1 R2 P2 R3 P3 Figure 5.8 Figure 5.9 Understanding Operating Systems

P1 P3    P2 P1 P3    P2 Figure 5.11 (a) Figure 5.11 (b)    Figure 5.11 (a) P2 P1 P3    Figure 5.11 (b) P2 Understanding Operating Systems

Strategies for Handling Deadlocks Prevent one of the four conditions from occurring. Avoid the deadlock if it becomes probable. Detect the deadlock when it occurs and recover from it gracefully. Understanding Operating Systems

Prevention of Deadlock To prevent a deadlock OS must eliminate 1 out of 4 necessary conditions. Same condition can’t be eliminated from every resource. Mutual exclusion is necessary in any computer system because some resources (memory, CPU, dedicated devices) must be exclusively allocated to 1 user at a time. Might be able to use spooling for some devices. May trade 1 type of deadlock (Case 3) for another (Case 5). Understanding Operating Systems

Prevention of Resource Holding or No Preemption Resource holding can be avoided by forcing each job to request, at creation time, every resource it will need to run to completion. Significantly decreases degree of multiprogramming. Peripheral devices would be idle because allocated to a job even though they wouldn't be used all the time. No preemption could be bypassed by allowing OS to deallocate resources from jobs. OK if state of job can be easily saved and restored. Bad if preempt dedicated I/O device or files during modification. Understanding Operating Systems

Prevention of Circular Wait Circular wait can be bypassed if OS prevents formation of a circle. Havender’s solution (1968) is based on a numbering system for resources such as: printer = 1, disk = 2, tape= 3. Forces each job to request its resources in ascending order. Any “number one” devices required by job requested first; any “number two” devices requested next … Require that jobs anticipate order in which they will request resources. A best order is difficult to determine. Understanding Operating Systems

Avoidance Even if OS can’t remove 1 conditions for deadlock, it can avoid one if system knows ahead of time sequence of requests associated with each of the active processes. Dijkstra’s Bankers Algorithm (1965) used to regulate resources allocation to avoid deadlock. Safe state -- if there exists a safe sequence of all processes where they can all get the resources needed. Unsafe state -- doesn’t necessarily lead to deadlock, but it does indicate that system is an excellent candidate for one. Understanding Operating Systems

Banker’s Algorithm Based on a bank with a fixed amount of capital that operates on the following principles: No customer will be granted a loan exceeding bank’s total capital. All customers will be given a maximum credit limit when opening an account. No customer will be allowed to borrow over the limit. The sum of all loans won’t exceed the bank’s total capital. OS (bank) must be sure never to satisfy a request that moves it from a safe state to an unsafe one. Job with smallest number of remaining resources < = number of available resources Understanding Operating Systems

Problems with Banker’s Algorithm 1. As they enter system, jobs must state in advance the maximum number of resources needed. 2. Number of total resources for each class must remain constant. 3. Number of jobs must remain fixed. 4. Overhead cost incurred by running the avoidance algorithm can be quite high. 5. Resources aren’t well utilized because the algorithm assumes the worst case. 6. Scheduling suffers as a result of the poor utilization and jobs are kept waiting for resource allocation. Understanding Operating Systems

Detection Use directed graphs to show circular wait which indicates a deadlock. Algorithm used to detect circularity can be executed whenever it is appropriate. Understanding Operating Systems

Reducing Directed Resource Graphs 1. Find a process that is currently using a resource and not waiting for one. Remove this process from graph and return resource to “available list.” 2. Find a process that’s waiting only for resource classes that aren’t fully allocated. Process isn’t contributing to deadlock since eventually gets resource it’s waiting for, finish its work, and return resource to “available list.” 3. Go back to Step 1 and continue the loop until all lines connecting resources to processes have been removed. Understanding Operating Systems

R1 P1 R2 P2 R3 P3 P2 P3 R1 P1 R2 R3 P2 P3 R1 P2 P3 R1 P1 R2 R3 P1 R2 Figure 5.12 (a) Figure 5.12 (b) P2 P3 R1 P2 P3 R1 P1 R2 R3 P1 R2 R3 Figure 5.12 (c) Figure 5.12 (d) Understanding Operating Systems

Recovery Once a deadlock has been detected it must be untangled and system returned to normal as quickly as possible. There are several recovery algorithms, all requiring at least one victim, an expendable job, which, when removed from deadlock, frees system. 1. Terminate every job that’s active in system and restart them from beginning. 2. Terminate only the jobs involved in deadlock and ask their users to resubmit them. Understanding Operating Systems

Recovery Algorithms - 2 3. Terminate jobs involved in deadlock one at a time, checking to see if deadlock is eliminated after each removal, until it has been resolved. 4. Have job keep record (snapshot) of its progress so it can be interrupted and then continued without starting again from the beginning of its execution. 5. Select a non-deadlocked job, preempt resources it’s holding, and allocate them to a deadlocked process so it can resume execution, thus breaking the deadlock 6. Stop new jobs from entering system, which allows non-deadlocked jobs to run to completion so they’ll release their resources (no victim).

Select Victim with Least-Negative Effect Priority of job under consideration—high-priority jobs are usually untouched. CPU time used by job—jobs close to completion are usually left alone. Number of other jobs that would be affected if this job were selected as the victim. Programs working with databases deserve special treatment. Understanding Operating Systems

Starvation Starvation -- result of conservative allocation of resources where a single job is prevented from execution because it’s kept waiting for resources that never become available. “The dining philosophers” Dijkstra (1968). Avoid starvation via algorithm designed to detect starving jobs which tracks how long each job has been waiting for resources (aging). Understanding Operating Systems