28 Pages

Deadlock

Course: CIS 361, Fall 2009
School: Delaware
Rating:
 
 
 
 
 

Word Count: 1203

Document Preview

of Deadlocks Lots resources can only be used by one process at a time. Exclusive access is needed. Suppose process A needs R1 + R2 and B needs R1 + R2. A gets R1, B gets R2 A waits for R2, B waits for R1 A and B can't continue without second resource and won't give up the one they have --> Deadlock Deadlocks Processes may be on same machine or distributed over a network. Resources may be hardware or...

Register Now

Unformatted Document Excerpt

Coursehero >> Delaware >> Delaware >> CIS 361

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
of Deadlocks Lots resources can only be used by one process at a time. Exclusive access is needed. Suppose process A needs R1 + R2 and B needs R1 + R2. A gets R1, B gets R2 A waits for R2, B waits for R1 A and B can't continue without second resource and won't give up the one they have --> Deadlock Deadlocks Processes may be on same machine or distributed over a network. Resources may be hardware or software (files, database). Some resources may be identical (have multiple of same) A preemptable resource can be taken away from a process and given back later with no problem (e.g. Memory) A nonpreemptable resource cannot be taken away without failure (CD, tape). Deadlocks Nonpreemptable resources are the kind that can cause deadlocks. Processes request a resource, use it, then release it. If the resource is not available the process must wait. Semaphores can be used to manage resources (init to 1) down the semaphore use resource up semaphore Deadlock-free code Semaphore R1, R2; void A() { down(R1); down(R2); Use(R1,R2); up(R2); up(R1); } void B() { down(R1); down(R2); Use(R1,R2); up(R2); up(R1); } Code with a possible deadlock Semaphore R1, R2; void A() { down(R1); down(R2); Use(R1,R2); up(R2); up(R1); } void B() { down(R2); down(R1); Use(R1,R2); up(R1); up(R2); } Deadlocks A set of processes is deadlocked when each process is waiting for a resource to be released by one of the other processes in the set. A B C N .... 4 conditions must hold to have a deadlock 1. Mutual Exclusion. - Process needs exclusive access to resources. 2. Hold and Wait. - Processes can request more resources while not giving any up. 3. No Preemption. - Can't take resources away from a process. 4. Circular wait. Each process is waiting on another process in the group. 4 conditions must hold to have a deadlock If any one of these conditions does not hold a deadlock is not possible. Just make one of them false and there's no deadlock. Any one of the 4. Not easy to do though. Deadlocks A B A holds R1 B is requesting R2 R1 R2 D R4 C R3 A cycle in a resource graph shows there is a deadlock. 4 strategies to deal with deadlocks 1. Ignore them. 2. Detect and recover. Let them happen, then do something about it. 3. Avoid by allocating resources carefully. 4. Prevent by making one of the 4 necessary conditions not hold. The Ostrich Algorithm Pretend there is no problem. Used by Unix and Windows. # of processes, # of files, + virtual mem have limits. Don't worry if a deadlock could happen. Detection and Recovery Allow deadlocks to happen, then do something to break it up. First consider all resources are unique (one of each type) Use a resource graph and look for cycles -> deadlock Need an algorithm to find cycles For the case of multiple resources of each type use an algorithm that is matrix based. Detection and Recovery N processes and M resource classes E = Existing resource vector [E1, E2, .., Em] A = Available resource vector [A1, A2, .. Am] C = Current allocation matrix (what processes currently have) C11 C12 .......................................C1m C21 C22 ........................................C2m . . . Cn1 Cn2 ........................................Cnm Detection and Recovery R = Request matrix (what processes need) R11 R12 .......................................R1m R21 R22 ........................................R2m . . . Rn1 Rn2 ........................................Rnm The algorithm compares vectors (A <= B means each element of A is <= to that position in B) Ai <= Bi, 1<=i <=m Detection and Recovery Each process starts off unmarked. The algorithm will mark processes that are not deadlocked. At end processes unmarked are deadlocked. 1. look for an unmarked process where its row in R is <= A. 2. If process is found mark it and add its row from C to A. 3. Otherwise algorithm ends. Unmarked processes are deadlocked. Detection and Recovery How often should that algorithm run? At every resource request? Works, but expensive. Or every few minutes or when cpu load is low maybe processes can't run so load is low. Other ideas? How to recover once deadlock is found? Preeemption take a resource away and give to another. Depends on resource if it will work or not. May need manual intervention. Rollback Checkpoint processes (save state so can be restarted there later) Then can rollback to that point if needed. Kill Processes until no more deadlock. Deadlock Avoidance Usually resources are requested one at a time rather than all at once. Avoid deadlocks by carefully allocating resources and only allocate them if a deadlock cannot result. Safe states are states where a deadlock does not have to happen there is some sequence where all the processes can run to completion. An unsafe state is a state where a deadlock may happen. Banker's Algorithm Deadlock avoidance algorithm that comes from Dijkstra. Works in the way a banker gives lines of credit to customers. It checks to see if a request would lead to an unsafe state. If so, the request is denied. Processes have a maximum claim for each resource. Banker's Algorithm Safe: Free = 2 Has Max A B C D 1 1 2 4 6 5 4 7 A B C D Unsafe: Free = 1 Has Max 1 2 2 4 6 5 4 7 Uses C, R, E and A from before + P = Possessed resources (E - A) Banker's Algorithm Algorithm for checking safety of a state: 1. Find a process from R that can have all its requests (max) filled. 2. Assume that process runs to completion. Add its resources to A. 3. Repeat 1 and 2 until all processes can run to completion (safe) or a deadlock happens (unsafe). Banker's Algorithm Example E = [ 8, 5, 9, 7 ], A = [ 1, 2, 2, 2 ] R P0 P1 P2 P3 P4 R0 3 0 5 1 3 R1 2 2 1 5 0 R2 1 5 0 3 3 R3 4 2 5 0 3 C P0 P1 P2 P3 P4 R0 2 0 4 0 1 R1 0 1 0 2 0 R2 1 2 0 1 3 R3 1 1 3 0 0 Claim Matrix Allocation Matrix Is this a safe or unsafe state? Banker's Algorithm Example ...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Delaware - CIS - 361
Zones - ContainersServer Consolidation Run multiple workloads on system Improve utilization of resources Reduce costs Run workloads in isolation Cannot observe others Security Isolation Running apps as different user not enough - privilege escalatio
Delaware - CIS - 361
Dining PhilosophersFive philosophers sit around a table with five forks and spaghetti to eat. Philosophers think for a while and they want to eat, only spaghetti, for a while. To eat a philosopher requires two forks, one from the left and one from r
Delaware - CIS - 361
The ShellWhat does a shell do? - execute commands, programs - but how? For built in commands run some code to do the command For other commands find program executable and . run it. Other features: wildcards, pipes, redirection.ProcessesThe shell
Delaware - CIS - 361
Architecture BackgroundVon Neumann architecture - cpu = ALU + control unit - memory - devices Above connected with buses ALU carry out instruction, may have more than one execution unit Program counter memory address of next instruction to fetch.
Delaware - CIS - 361
Chapter 2 Process, Thread and Scheduling Soloris IPC1Outline Generic System V IPC Support Shared Memory System V Semaphores System V Message Queues POSIX IPC Signal Door2Generic System V IPC SupportModule TheCreationSystem V IPC
Delaware - CIS - 361
Chapter 2 Process, Thread and Scheduling - Scheduler Class and PriorityXIANG Yong xyong@tsinghua.edu.cnOutline Scheduling Class and Priority Dispatch Queues &amp; Dispatch Tables Thread Priorities &amp; Scheduling Turnstiles &amp; Priority Inheritance2
Delaware - CIS - 361
Operating Systems Update: Solaris, OpenSolaris, LinuxHarry J Foxwell, PhD OS AmbassadorSun Microsystems Federal, IncSolaris 10 Introduced in Jan 05, included:&gt; Containers: OS virtualization for isolation &gt; &gt; &gt; &gt; &gt;consolidation/utilization Obs
Delaware - CIS - 361
Name:UDel CISC361-010 Midterm, March 24, 2005Be sure that you read each question and understand what it is asking. No calculators permitted. 1. (10 pts) True/False (circle T for True, F for False) (a) T F - The C shell (csh) is derived from the Bo
Delaware - CIS - 361
Chapter 2 Process, thread, and scheduling - Solaris Multithreaded ProcessZhao Xia zhaoxia@os.pku.edu.cnOutline Introduction to Solaris Processes Multithreaded Process Model Proc tools2The Process ModelSolarisKernel is Multi-threadedK
Delaware - CIS - 361
Name:Show your work! Partial credit will be given, but only if you show your work!. Be sure that you read each question and understand what it is asking.UDel CISC361-010 Final, December 13, 20011. 10 pts True False a T F - Segmentation is just a
Delaware - CIS - 361
ZFSNew filesystem and volume manager from Sun Open source after 5 years development First appeared in OpenSolaris, later in Solaris 10 6/06 (u2). Has been ported to FreeBSD. Also being including on Macs in the works (Leopard*) Linux FUSE port Jeff B
Delaware - CIS - 361
UDel CISC361Study Operating System principles - processes, threads - scheduling - mutual exclusion - synchronization - deadlocks - memory management - file systems - security - networking (if time allows)Operating SystemsUse of Solaris - advanced
Delaware - CIS - 361
Zones - ContainersServer Consolidation Run multiple workloads on system Improve utilization of resources Reduce costs Run workloads in isolation Cannot observe others Security Isolation Running apps as different user not enough - privilege escalatio
Delaware - CIS - 361
Architecture BackgroundVon Neumann architecture - cpu = ALU + control unit - memory - devices Above connected with buses ALU carry out instruction, may have more than one execution unit Program counter memory address of next instruction to fetch.
Delaware - CIS - 361
UDel CISC361-010 Midterm, October 24, 2001Show your work. Partial credit will be given, but only if you show your work. Be sure that you read each question and understand what it is asking.Name:1.10 ptsa b c d e f g h i j 2.True False T F
Delaware - CIS - 105
CISC 105 Fall 2005Name Circle section: 18 19 20 21Midterm 110/07/05TAGeneral Instructions DO NOT PUT YOUR SSN ON ANYTHING! DO NOT WRITE YOUR NAME ON ANY PAGE EXCEPT THIS ONE! Turn off any noise making device, especially CELL PHONES. You m
Delaware - CIS - 105
CISC105 Spring 2007 Lab11 This lab is designed to help with your project. Youll write small programs that demonstrate things you are supposed to do in the project. In general, writing small test programs that demonstrate the concepts you want to emp
Delaware - CIS - 105
CISC105 Spring 2007 Lab06 CODE! If you are having difficulty writing programs, consider programming more often. Working on C every day makes a big difference, and leaving it alone, even just for a weekend, can result in backsliding. You are learning
Delaware - CIS - 181
CISC181 Spring 2008 Lab02 If you did not use the SunRays in CISC105 or 106, then see Lab00 from this directory. Lab00 also reviews compiling and running C+ programs on Unix. This lab should be a review of programming concepts you have seen before.
Delaware - CIS - 181
Project 2, CISC181 Spring 08Domain choice due by email (see below) April 14th Testing and makefile due Thursday April 24th midnight, paper Friday in class Due Sunday April 27th midnight, paper Monday in class AssignmentPlease read the online FAQ fo
Delaware - CIS - 181
CISC181 Fall 2008 Lab01 See Lab00 if you would like to review compiling and running C+ programs on Unix. Be sure to change your disk quota as I described in an email to you last week. Remember, never delete an email from your professor or TA. Thi
Delaware - CIS - 181
Every problem starts with the same picture. Given the code, modify the picture to show what happens. Be sure to struct Node { 1) cross out pointers that go away; int data; 2) add any new pointers, structs, or data; Node * next; 3) follow the code, no
Delaware - CIS - 181
CISC181 Fall 2006 Lab02 Write a program for each of the following problems. Be sure to save every separate program. All programs must be properly commented and indented (see Assignment Standards on the class website). Ask your TA for guidance. Read
Delaware - CIS - 181
CISC181 Fall 2006 Lab09 Write a program for each of the following problems. Be sure to save every separate program. All programs must be properly commented and indented (see Assignment Standards on the class website). Ask your TA for guidance. Feel
Delaware - CIS - 181
181 Quiz 4/11/08 10 pts. Name Section TA1. Show an expression that puts a pseudo-random number into x: int x;2. The C+ language builds on C by adding three features, according to our discussion in class: inheritance, polymorphism, and 1 2 3 4 5 6
Delaware - CIS - 181
181 Quiz 5/9/08 10 pts. Name Section TA Consider the class below which has functions for addition and multiplication. class Rat{ int num; int denom; public: Rat(int n = 0, int d = 1):num(n),denom(d){} Rat operator+(const Rat&amp; rhs); friend Rat operato
Delaware - CIS - 181
Every problem starts with the same picture. Given the code, modify the picture to show what happens. Be sure to struct Node { 1) cross out pointers that go away; int data; 2) add any new pointers, structs, or data; Node * next; 3) follow the code, no
Delaware - CIS - 181
CISC 181 Fall 2006First Midterm Learning Experience10/9/06NameLogin nameSection:TAGeneral Instructions DO NOT PUT YOUR SSN ON ANYTHING! DO NOT WRITE YOUR NAME ON ANY PAGE EXCEPT THIS ONE! Turn off any noise making device, especially
Delaware - CIS - 181
CISC181 Spring 2008 Lab01 If you did not use the SunRays in CISC105 or 106, then see Lab00 from this directory. Lab00 also reviews compiling and running C+ programs on Unix. During lab, your TA will explain how to check your disk quota, and what to
Delaware - CIS - 181
CISC181 Spring 2008 Lab03 If your SunRay sessions are behaving oddly, please check your disk usage (see lab00). If your quota is ok, then you may need to check your dot les (.login, .localenv, .cshrc, etc). This information is also available from th
Delaware - CIS - 181
CISC181 Spring 2008 Lab07 Debugging? INSERT PRINT STATEMENTS. Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Name each program lab07.n.cc
Delaware - CIS - 181
CISC181 Spring 2008 Lab06 Debugging? INSERT PRINT STATEMENTS. Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program le. Your answers will be graded. Name each program lab06.n.cc,
Delaware - CIS - 181
CISC181 Spring 2008 Lab05 Debugging? INSERT PRINT STATEMENTS. Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program le. Your answers will be graded. EVERY program you write in thi
Delaware - CIS - 181
CISC181 Spring 2008 Lab08 Debugging? INSERT PRINT STATEMENTS. Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Most of this lab will help y
Delaware - CIS - 181
CISC181 Spring 2008 Lab09 Debugging? INSERT PRINT STATEMENTS. Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program le. Your answers will be graded. Most of this lab will help you
Delaware - CIS - 181
CISC181 Spring 2008 Lab11 Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Name each program lab11.n.cc, where n is the number in the list b
Delaware - CIS - 181
CISC181 Spring 2008 Lab04 If your loop or recursion doesn't stop, then insert a print statement showing the values of your control variables before, during, and after the loop. Information is free! And it beats staring at code when you are tired. S
Delaware - CIS - 181
CISC181 Spring 2008 Lab12 Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Name each program lab12.n.cc, where n is the number in the list b
Delaware - CIS - 181
181 Leap Day Quiz 2/29/08 10 pts. Name Section TA1. Suppose you call a binary search function on an array of size 128. What is the maximum number of comparisons the code will have to make, according to our discussion in class? 2. Fill in the two bl
Delaware - CIS - 181
181 Quiz 3/28/08 10 pts. Name Section TA1. 4 Dene a struct type that will hold a student name and id number.2. 3 Declare one student and ll with data.3. 3 Declare a second student, and give it the same values as the rst without restating those
Delaware - CIS - 181
181 Quiz 5/9/08 12 pts. Name Section TAclass Flour{ private: int weight; int getWeight(){return weight;} public: Flour():weight(5){} int getWeight2(){return weight;} void say(){cout &lt; &quot;I am a Flour object\n&quot;;} virtual void say2(){cout &lt; &quot;I am a Flo
Delaware - CIS - 181
181 Quiz 3/11/08 10 pts. Name Use only the names provided! Section TAOn the four lines provided, write four single C+ statements to: 1. Declare an integer named i and initialize it to 272. Declare a pointer ip and initialize it to point to i3.
Delaware - CIS - 181
181 Quiz 2/22/08 10 pts. Name Lab Section TA1. In C+ the operators &amp; and | both evaluate their second arguments only if it is necessary. This is called: 2. Write what this code fragment, a C+ if statement, will print, or write &quot;error&quot; if it won't c
Delaware - CIS - 181
181 Quiz 2/22/08 10 pts. Name Lab Section TA1. According to the Structured Programming model, there are three ways to control program flow. What are they? 2. Write what this code fragment, a C+ if statement, will print, or write &quot;error&quot; if it won't
Delaware - CIS - 181
CISC181 Fall 2008 Lab04 If you have not read the project document online, stop reading this and READ THE PROJECT RIGHT NOW. There are important deadlines tomorrow (Friday). Your book is an excellent resource. I nd the table of contents very good, a
Delaware - CIS - 181
CISC181 Fall 2008 Lab10 Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program le. Your answers will be graded. Dont answer questions in parentheses. Name each program lab10.n.cc, w
Delaware - CIS - 181
Project 3, CISC181 Fall 08Dec 1, 5, 6Submission dates. Submit any code you (an individual) have written as of the deadline, just to prove you are doing something.Due Sunday Dec 7th midnight, paper code copy in class MondayYou must execute the sp
Delaware - CIS - 181
CISC 181 Spring 2008Second Midterm Learning Experience4/28/08Name Section: TALogin nameGeneral Instructions DO NOT PUT YOUR SSN ON ANYTHING! DO NOT WRITE YOUR NAME ON ANY PAGE EXCEPT THIS ONE! Turn off any noise making device, especially
Delaware - CIS - 181
CISC181 Fall 2008 Lab09 Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program le. Your answers will be graded. Dont answer questions in parentheses. Name each program lab09.n.cc, w
Delaware - CIS - 181
Project 2, CISC181 Fall 08All testing code, stubs and makefile due Friday Nov 7 midnight, paper in class Due Sunday Nov 16th midnight, paper code copy in class Monday AssignmentPlease read the online FAQ for this project, which I will add to as I r
Delaware - CIS - 181
CISC181 Fall 2008 Lab06 Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Don't answer questions in parentheses. Name each program lab06.n.cc
Delaware - CIS - 181
CISC 181 Practice Fall 2008Concluding Learning Experience5/27/08NameLogin nameLecture Section:TAGeneral Instructions DO NOT PUT YOUR SSN ON ANYTHING! DO NOT WRITE YOUR NAME ON ANY PAGE EXCEPT THIS ONE! Turn off any noise making devic
Delaware - CIS - 181
CISC181 Fall 2008 Lab07 Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Don't answer questions in parentheses. Name each program lab07.n.cc
Delaware - CIS - 181
CISC181 Fall 2008 Project 3 Script Steps Names: Create a script file with each one of these actions completed. Do not print the script file, but submit it with your code on Sakai. Check each box as you do the action in your script, and submit the com
Delaware - CIS - 181
CISC 181 Spring 2008First Midterm Learning Experience3/18/08NameLogin nameSection:TAGeneral Instructions DO NOT PUT YOUR SSN ON ANYTHING! DO NOT WRITE YOUR NAME ON ANY PAGE EXCEPT THIS ONE! Turn off any noise making device, especiall
Delaware - CIS - 181
CISC181 Fall 2008 Lab08 Beta Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Don't answer questions in parentheses. Name each program lab08
Delaware - CIS - 181
CISC181 Fall 2008 Lab05 Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program le. Your answers will be graded. Dont answer questions in parentheses. Name each program lab05.n.cc, w
Delaware - CIS - 181
CISC181 Spring 2008 Lab11 Debugging? INSERT PRINT STATEMENTS. Some programs below are associated with a question. Answer the questions using C+ comments below your code in the program file. Your answers will be graded. Keep track of why we do thin
Delaware - CIS - 181
CISC181 Fall 2008 Project 1Testing code due Oct 12 Enhancement description due Oct 12 Project due Oct 16th OverviewYour project will simulate a bear moving in a 2-d plane. The bear can see all food on the plane, and will move towards the nearest fo
Delaware - CIS - 181
CISC181 Fall 2008 Lab02 This lab should be a review of programming concepts you have seen before. If these concepts are not familiar, see the instructor. Write programs as required for the following problems. If you wish, you may start each program
Delaware - CIS - 181
CISC181 Fall 2008 Lab03 If your SunRay sessions are behaving oddly, please check your disk usage (see lab00). If your quota is ok, then you may need to check your dot files (.login, .localenv, .cshrc, etc). This information is also available from th