Operating Systems Deadlock
Operating Systems Deadlock
Collage of Education
Computers Science Department
• Sometimes, a waiting process is never again able to change state, because the
resources it has requested are held by other waiting processes. This situation
is called a deadlock.
ألن الم"وارد ال"تي، ال"تي تنتظ"ر ان تغ"ير حالته"اprocess ال يمكن ل"ل، • في بعض األحي"ان
تس""مى ه""ذه الحال""ة. أخ""رىwaiting processes طلبته""ا يتم االحتف""اظ به""ا بواس""طة
Deadlock
• operating systems typically do not provide deadlock-prevention facilities, and it
remains the responsibility of programmers to ensure that they design deadlock-
free programs.
ويبقى من مس""ؤولية، Deadlock • ال ت""وفر أنظم""ة التش""غيل ع""ادًة تس""هيالت من""ع ال
.Deadlock المبرمجين التأكد من تصميم برامج خالية من ال
6.1.1. System Model
• System consists of a finite number of resources
• Resource types R1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
• Each resource type Ri has Wi instances.
2. Use: The process can operate on the resource (for example, if the resource is
a printer, the process can print on the printer).
, printer اذا كان المورد هو: ( كمثال. أستخدام الموردprocess • تستطيع الـ
. Printer الطباعة على هذه الـprocess فتستطيع الـ
•An assignment edge must also designate one of the dots in the rectangle (instance).
When process Pi, requests an instance of resource type Rj, a request edge is inserted in
the resource-allocation graph. When this request can be fulfilled, the request edge is
instantaneously transformed to an assignment edge.
When the process no longer needs access to the resource, it releases the resource; as a
result, the assignment edge is deleted.
RESOURCE ALLOCATION GRAPH EXAMPLE
The resource-allocation graph shown in the figure 6.1 depicts the following
• situation
The sets P, R, and E:
- P = {P1, P2, P3}
- R = {R1, R2 ,R3, R4}
- E = {P1 →R1, P2 → R3, R1 → P2, R2 → P2, R2 → P1,
R3 →P3 }
• Resource instances:
- One instance of resource type R1
- Two instances of resource type R2
- One instance of resource type R3
Figure 6.1
- Three instances of resource type R4
• Process states:
- Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type
R1.
- Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an instance of R3.
- Process P3 is holding an instance of R3.
Given the definition of a resource-allocation graph, it can
be shown that, if the graph contains no cycles, then no
process in the system is deadlocked. If the graph does
contain a cycle, then a deadlock may exist.
If each resource type has exactly one instance, then a
cycle implies that a deadlock has occurred. Each process
involved in the cycle is deadlocked.
If each resource type has several instances, then a cycle
does not necessarily imply that a deadlock has occurred.
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
End of Part1