{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture29 - Quiz#2 is graded Wednesday June 3 Project#4...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Quiz #2 is graded Wednesday, June 3 Project #4 Check scores Homework #5 is posted Due tonight before midnight Evaluation criteria are posted Credit Distribution Agreement (hardcopy) is due by end of class Friday Review document is due by midnight Friday Discussion in class Friday Solutions will be posted Do the Projects Survey Wednesday, June 3 Other evaluations Responses are posted on the wiki Contribution credit Today: Instructor Friday: LearningObjectives No office hours Friday Extra hours Thursday, Monday Paulson: Today's topics Classical problems in synchronization Deadlock Resource Allocation Graphs Instructor Evaluation ReadersWriters Problem Shared data semaphore mutex, wrt; int readcount; Initially mutex = 1, wrt = 1, readcount = 0 wait, signal Think of "wait" as "try to grab" Think of "signal" as "release" ReadersWriters Problem: Writer Process wait(wrt); // Waits until wrt > 0 // Decrements wrt signal(wrt); // Increments wrt ... ReadersWriters Problem: Reader Process wait(mutex); readcount++; if (readcount == 1) wait(wrt); signal(mutex); // reading is performed wait(mutex); readcount; if (readcount == 0) signal(wrt); signal(mutex): Writer Process wait(wrt); // writing is performed signal (wrt) ; DiningPhilosophers Problem Shared data Initially all chopstick values are 1 semaphore chopstick[5]; Process for Philosopher i : wait(chopstick[i]) wait(chopstick[(i+1) % 5]) //eat DiningPhilosophers Problem (semaphores) signal(chopstick[i]); signal(chopstick[(i+1) % 5]); Animations readerswriters dining philosophers Starvation Indefinite blocking. A process is ready to be executed, but the required resources are held by other processes e.g., CPU timeslice, etc. Might eventually get required resources e.g., priority upgrade, etc. The Deadlock Problem Given a set of blocked processes ... Example If each process in the set is holding a resource and is waiting to acquire a resource held by another process in the set, deadlock occurs. System has 2 semaphores. P1 and P2 each hold one semaphore and each needs the other one. Note: circular waiting can occur among multiple processes Deadlock Two or more processes are waiting for an event that can only be caused by one of the other waiting processes Let S and Q be two semaphores initialized to 1 P0 wait (S); wait (Q); . . signal (S); signal (Q); P1 wait (Q); wait (S); . . signal (Q); signal (S); Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. 1. 2. 3. 4. Mutual exclusion: at least one resource currently in use must forbid concurrent access 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 after the process holding it has completed its task. (voluntary release) Circular wait: there exists a set {P0, P1, ..., Pn} of waiting processes such that P0 is waiting for a resource that is held by P1 P1 is waiting for a resource that is held by P2 ... Pn1 is waiting for a resource that is held by Pn Pn is waiting for a resource that is held by P0. Note: There are no additional instances of the resources types for which the processes P0 ... Pn are waiting. Traffic Deadlock 1. 2. 3. 4. What are the processes? What are the resources? How is mutual exclusion a factor? How is hold & wait a factor? How is no preemption a factor? How is circular wait a factor? System Model Resource types R1, R2, . . ., Rm Each resource type Ri has Wi instances. Each process utilizes a resource as follows: Semaphores, CPU cycles, memory space, I/O devices request use release ResourceAllocation Graph A set of vertices V and a set of edges E. V is partitioned into two types: request edge directed edge Pi Rj P = {P1, P2, ..., Pn}, the set consisting of all the processes in the system. R = {R1, R2, ..., Rm}, the set consisting of all resource types in the system. Each Rj has Wj instances assignment edge directed edge Rj Pi ResourceAllocation Graph Process Resource Type (with 4 instances) Pi requests an instance of Rj (request edge) Pi Rj Wj = 4 Pi holds an instance of Rj (assignment edge) Pi Rj Example of a Resource Allocation Graph Resource Allocation Graph With Deadlock Resource Allocation Graph With A Cycle But No Deadlock Basic Facts If the graph contains no cycles, then no deadlock. If the graph contains at least one cycle AND each resource type has only one instance, then deadlock. If the graph contains at least one cycle AND some resource types have multiple instances, then possibility of deadlock. 1. 2. 3. Ensure that the system will never enter a deadlock state. (deadlock prevention/avoidance) Allow the system to enter a deadlock state and then recover. (deadlock detection/recovery) Make an effort to prevent/avoid, but basically ignore the problem and pretend that deadlocks never occur in the system Methods for Handling Deadlocks used by most operating systems Deadlock Prevention Restrain the ways request can be made. Can not restrain Mutual Exclusion To restrain Hold and Wait must be enforced for shared resources that may be changed. must guarantee that whenever a process requests a resource, it does not hold any other resources. Low resource utilization require process to request and be allocated all its resources before it begins execution allow process to request resources only when it does not hold any resources. (release before request) Deadlock Prevention (Cont.) To restrain No Preemption If a process holding some resources requests an additional resource that cannot be immediately allocated to it, then all resources currently being held by that process are released. Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting. Low resource utilization starvation possible. Deadlock Prevention (Cont.) To restrain Circular Wait Impose a total ordering of all resource types Problem with complexity require that each process request resources in an increasing order of enumeration. Note: Defeat any one (or more) of these conditions, and deadlock does not occur Questions? Do Homework #5 Discussion in class Friday Instructor Evaluation ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online