Download presentation
Presentation is loading. Please wait.
Published byTabitha Waterbury Modified over 9 years ago
1
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.1 Operating System Concepts Operating Systems Lecture 27 CPU Simulator III Deadlock
2
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.2 Operating System Concepts handle_run_term( ) We will determine what needs to be done for this function in class.
3
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.3 Operating System Concepts handle_run_block( ) We will determine what needs to be done for this function in class.
4
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.4 Operating System Concepts handle_block_ready( ) We will determine what needs to be done for this function in class.
5
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.5 Operating System Concepts Files, etc. Place all the code for the fcfs simulation in the file"fcfs.cc" In driver.cc, you should have an include line: #include "fcfs.cc" To compile, you can type: g++ driver.cc -o sim Place all struct definitions and enums in a file "sim.h" Include "sim.h" in both driver.cc and fcfs.cc You will need to use #ifndef SIM_H, etc. to make sure the linker doesn't complain. Use the following include lines in sim.h: #include "nextEvent.h" #include "list.h" Do not include nextEvent.h or list.h in driver.cc or fcfs.cc
6
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.6 Operating System Concepts Developing your code Write your functions one at a time. Debug each function before you start working on the next. Example: Make sure your function to initialize the Event queue inserts all the appropriate events based on the process arrival times before you try to right any of the event handlers. Use cout statements and the display( ) function (part of the NextEventSimulator and the list classes) to make sure your function is doing the right thing.
7
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.7 Operating System Concepts The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. Example System has 2 tape drives. P 1 and P 2 each hold one tape drive and each needs another one. Example semaphores A and B, initialized to 1 P 0 P 1 wait (A);wait(B) wait (B);wait(A)
8
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.8 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section of a bridge can be viewed as a resource. If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). Several cars may have to be backed up if a deadlock occurs. Starvation is possible.
9
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.9 Operating System Concepts System Model Resource types R 1, R 2,..., R m CPU cycles, memory space, I/O devices Each resource type R i has W i instances. Each process utilizes a resource as follows: request use release
10
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.10 Operating System Concepts Deadlock Characterization Mutual exclusion: only one process at a time can use a resource. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. Circular wait: there exists a set {P 0, P 1, …, P n } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, …, P n–1 is waiting for a resource that is held by P n, and P n is waiting for a resource that is held by P 0. Deadlock can arise if four conditions hold simultaneously.
11
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.11 Operating System Concepts Resource-Allocation Graph V is partitioned into two types: P = {P 1, P 2, …, P n }, the set consisting of all the processes in the system. R = {R 1, R 2, …, R m }, the set consisting of all resource types in the system. request edge – directed edge P i R j assignment edge – directed edge R j P i A set of vertices V and a set of edges E.
12
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.12 Operating System Concepts Resource-Allocation Graph (Cont.) Process Resource Type with 4 instances P i requests instance of R j P i is holding an instance of R j PiPi PiPi RjRj RjRj
13
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.13 Operating System Concepts Example of a Resource Allocation Graph
14
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.14 Operating System Concepts Resource Allocation Graph With A Deadlock
15
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.15 Operating System Concepts Resource Allocation Graph With A Cycle But No Deadlock
16
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.16 Operating System Concepts Basic Facts If graph contains no cycles no deadlock. If graph contains a cycle if only one instance per resource type, then deadlock. if several instances per resource type, possibility of deadlock.
17
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.17 Operating System Concepts Methods for Handling Deadlocks Ensure that the system will never enter a deadlock state. Allow the system to enter a deadlock state and then recover. Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.