1 pertemuan 10 deadlock (lanjutan) matakuliah: t0316/sistem operasi tahun: 2005 versi/revisi: 5
TRANSCRIPT
![Page 1: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/1.jpg)
1
Pertemuan 10Deadlock (lanjutan)
Matakuliah : T0316/sistem Operasi
Tahun : 2005
Versi/Revisi : 5
![Page 2: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/2.jpg)
2
Learning Outcomes
Pada akhir pertemuan ini, diharapkan mahasiswa
akan mampu :• mendemonstrasikan cara menghindari deadlock
(C3)
![Page 3: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/3.jpg)
3
Outline Materi
• Deadlock Avoidance• Safe and Unsafe states• Algoritma Banker• Deadlock Prevention• Isu-isu yg berhubungan dgn deadlock
![Page 4: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/4.jpg)
4
Deadlock Avoidance
Two process resource trajectories
Resource Trajectories
![Page 5: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/5.jpg)
5
Safe and Unsafe States (1)
Demonstration that the state in (a) is safe
(a) (b) (c) (d) (e)
![Page 6: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/6.jpg)
6
Safe and Unsafe States (2)
Demonstration that the state in b is not safe
(a) (b) (c) (d)
![Page 7: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/7.jpg)
7
The Banker's Algorithm for a Single Resource
• Three resource allocation states– safe– safe– unsafe
(a) (b) (c)
![Page 8: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/8.jpg)
8
Banker's Algorithm for Multiple Resources
Example of banker's algorithm with multiple resources
![Page 9: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/9.jpg)
9
Deadlock Prevention
• Some devices (such as printer) can be spooled– only the printer daemon uses printer resource– thus deadlock for printer eliminated
• Not all devices can be spooled• Principle:
– avoid assigning resource when not absolutely necessary
– as few processes as possible actually claim the resource
Attacking the Mutual Exclusion Condition
![Page 10: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/10.jpg)
10
Attacking the Hold and Wait Condition
• Require processes to request resources before starting– a process never has to wait for what it needs
• Problems– may not know required resources at start of run– also ties up resources other processes could be using
• Variation: – process must give up all resources– then request all immediately needed
![Page 11: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/11.jpg)
11
Attacking the No Preemption Condition
• This is not a viable option
• Consider a process given the printer– halfway through its job– now forcibly take away printer– !!??
![Page 12: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/12.jpg)
12
Attacking the Circular Wait Condition (1)
(a) Normally ordered resources
(b) A resource graph
(a) (b)
![Page 13: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/13.jpg)
13
Attacking the Circular Wait Condition (2)
Summary of approaches to deadlock prevention
![Page 14: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/14.jpg)
14
Other Issues
• Phase One– process tries to lock all records it needs, one at a time– if needed record found locked, start over– (no real work done in phase one)
• If phase one succeeds, it starts second phase, – performing updates– releasing locks
• Note similarity to requesting all resources at once• Algorithm works where programmer can arrange
– program can be stopped, restarted
Two-Phase Locking
![Page 15: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/15.jpg)
15
Nonresource Deadlocks
• Possible for two processes to deadlock– each is waiting for the other to do some
task
• Can happen with semaphores– each process required to do a down() on
two semaphores (mutex and another)– if done in wrong order, deadlock results
![Page 16: 1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5](https://reader031.vdocuments.site/reader031/viewer/2022013011/56649f0c5503460f94c1ff68/html5/thumbnails/16.jpg)
16
Starvation
• Algorithm to allocate a resource – may be to give to shortest job first
• Works great for multiple short jobs in a system• May cause long job to be postponed
indefinitely– even though not blocked
• Solution:– First-come, first-serve policy