Modern Operating Systems by Herbert Bos ...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Showing 466-467 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 466
6
DEADLOCKS
Computer systems are full of resources that can be used only by one process at
a time. Common examples include printers, tape drives for backing up company
data, and slots in the system’s internal tables.
Having two processes simultan-
eously writing to the printer leads to gibberish.
Having two processes using the
same file-system table slot invariably will lead to a corrupted file system.
Conse-
quently, all operating systems have the ability to (temporarily) grant a process ex-
clusive access to certain resources.
For many applications, a process needs exclusive access to not one resource,
but several. Suppose, for example, two processes each want to record a scanned
document on a Blu-ray disc.
Process
A
requests permission to use the scanner and
is granted it.
Process
B
is programmed differently and requests the Blu-ray re-
corder first and is also granted it.
Now
A
asks for the Blu-ray recorder, but the re-
quest is suspended until
B
releases it.
Unfortunately, instead of releasing the Blu-
ray recorder,
B
asks for the scanner.
At this point both processes are blocked and
will remain so forever. This situation is called a
deadlock
.
Deadlocks can also occur across machines.
For example, many offices have a
local area network with many computers connected to it.
Often devices such as
scanners, Blu-ray/DVD recorders, printers, and tape drives are connected to the
network as shared resources, available to any user on any machine. If these de-
vices can be reserved remotely (i.e., from the user’s home machine), deadlocks of
the same kind can occur as described above.
More complicated situations can
cause deadlocks involving three, four, or more devices and users.
435


Page 467
436
DEADLOCKS
CHAP. 6
Deadlocks can also occur in a variety of other situations..
In a database sys-
tem, for example, a program may have to lock several records it is using, to avoid
race conditions.
If process
A
locks record
R1
and process
B
locks record
R2
, and
then each process tries to lock the other one’s record, we also have a deadlock.
Thus, deadlocks can occur on hardware resources or on software resources.
In this chapter, we will look at several kinds of deadlocks, see how they arise,
and study some ways of preventing or avoiding them.
Although these deadlocks
arise in the context of operating systems, they also occur in database systems and
many other contexts in computer science, so this material is actually applicable to a
wide variety of concurrent systems.
A great deal has been written about deadlocks.
Two bibliographies on the sub-
ject have appeared in
Operating Systems Review
and should be consulted for refer-
ences (Newton, 1979; and Zobel, 1983).
Although these bibliographies are very
old, most of the work on deadlocks was done well before 1980, so they are still
useful.
6.1 RESOURCES
A major class of deadlocks involves resources to which some process has been
granted exclusive access. These resources include devices, data records, files, and
so forth.
To make the discussion of deadlocks as general as possible, we will refer
to the objects granted as
resources
.
A resource can be a hardware device (e.g., a
Blu-ray drive) or a piece of information (e.g., a record in a database).
A computer
will normally have many different resources that a process can acquire.
For some
resources, several identical instances may be available, such as three Blu-ray
drives. When several copies of a resource are available, any one of them can be
used to satisfy any request for the resource.
In short, a resource is anything that
must be acquired, used, and released over the course of time.
6.1.1 Preemptable and Nonpreemptable Resources
Resources come in two types: preemptable and nonpreemptable.
A
preempt-
able resource
is one that can be taken away from the process owning it with no ill
effects. Memory is an example of a preemptable resource.
Consider, for example,
a system with 1 GB of user memory, one printer, and two 1-GB processes that each
want to print something.
Process
A
requests and gets the printer, then starts to
compute the values to print.
Before it has finished the computation, it exceeds its
time quantum and is swapped out to disk.
Process
B
now runs and tries, unsuccessfully as it turns out, to acquire the
printer.
Potenially, we now have a deadlock situation, because
A
has the printer
and
B
has the memory, and neither one can proceed without the resource held by
the other.
Fortunately, it is possible to preempt (take away) the memory from
B
by


Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Great resource for chem class. Had all the past labs and assignments
Leland P.
Santa Clara University
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades

Students also viewed documents