Professional Documents
Culture Documents
CS 241 Lecture 15
T: Ch 3, pp 159-183
Roy Campbell
4/24/2012
Discussion
Operating systems acquire dedicated access to shared resources
How can conflicts arise? How can you prevent conflicts?
4/24/2012
Contents
Definitions Resources Conditions for deadlock Deadlock issues
4/24/2012
Definitions
A process is deadlocked if it is waiting for an event that will never occur Typically, but not necessarily, more than one process will be involved together in a deadlock (the deadly embrace)
4/24/2012
Example - Contention
Synchronization Deadlock
1 2 3 4 5
2 3 4 5
4/24/2012
0 6
External Semaphore A(1), B(1); External Semaphore A(0), B(1); External Semaphore A(0), B(0); External Semaphore A(0), B(1); External Semaphore A(1), B(1);
CS241 2005 Roy Campbell, All Rights Reserved 6
Synchronization Deadlock
1 2 Process P(); { A.P(); B.P(); B.V(); A.V(); } 1 3
Process Q(); { B.P(); A.P(); A.V(); B.V(); }
1 External Semaphore A(1), B(1); 2 External Semaphore A(0), B(1); 3 External Semaphore A(0), B(0);
4/24/2012 CS241 2005 Roy Campbell, All Rights Reserved 7
Definitions
A process is indefinitely postponed if it is delayed repeatedly over a long period of time while the attention of the system is given to other processes i.e., Logically the process may proceed but the system never gives it the CPU
4/24/2012
Resources
A resource is a commodity needed by a process Habermann: ``resources work by order of a process or another resource; processes do not
4/24/2012
Resources
Resources can be either: Serially reusable: e.g., CPU, memory, disk space, I/O devices, files
Acquire use release
4/24/2012
10
Resources
Or: Consumable: produced by a process, needed by a process; e.g., Messages, buffers of information, interrupts
Create acquire use (resource ceases to exist after it has been used, so it is not released. )
4/24/2012
11
Resources
Resources can also be either: Pre-emptible: e.g., CPU, central memory Non-pre-emptible: e.g., Tape drives
4/24/2012
12
Resources
Or resources can be: Shared among several processes Dedicated exclusively to a single process
4/24/2012
13
4/24/2012
14
Mutual Exclusion
Processes claim exclusive control of the resources they require
4/24/2012
15
Wait-for Condition
Processes hold resources already allocated to them while waiting for additional resources
4/24/2012
16
4/24/2012
17
No Preemption Condition
Resources cannot be removed from the processes holding them until used to completion
4/24/2012
18
Its difficult to take a tape drive away from a process that is busy writing a tape
4/24/2012
19
A circular chain of processes exists in which each process holds one or more resources that are requested by the next process in the chain
4/24/2012
20
4/24/2012
21
Summary
Definitions Resources Conditions for deadlock Deadlock issues
4/24/2012
22