6. konkurensi_deadlock & starvation (pert 9 & 10)
DESCRIPTION
Materi elearning SISOPTRANSCRIPT
![Page 1: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/1.jpg)
SISTEM OPERASI
TIM DOSEN PENGAMPU SISTEM OPERASI
Konkurensi:
Deadlock & Starvation
Fakultas InformatikaSarjana Teknik Informatika
Pertemuan 8 & 9
![Page 2: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/2.jpg)
Daftar Isi
1. Prinsip Prinsip Deadlock
2. Deadlock Prevention
3. Deadlock Avoidance
4. Deadlock Detection
5. Perbandingan Metode Penanganan Deadlock
6. Kasus Dinning Philosopher
![Page 3: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/3.jpg)
1. Definisi dan Konsep Deadlock
2. Joint Progress Diagram (JPD)3. Reusable Resources
4. Consumable Resources
5. Resource Allocation Graphs (RAG)
6. Kondisi Deadlock
Prinsip Prinsip Deadlock
![Page 4: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/4.jpg)
Definisi dan Konsep Deadlock
Deadlock adalah kondisi dimana sejumlah proses ter-bloksecara permanen akibat saling memperebutkan atau salingmenunggu pesan / resource
Definisi
Tidak ada solusi yang efisienSolusi
Deadlock prevention
Deadlock avoidance
Deadlock detection
![Page 5: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/5.jpg)
Contoh AnalogiDeadlock
Deadlock Possible
Deadlock
![Page 6: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/6.jpg)
Contoh Deadlock
P1 P2
Ra Rb
get bget a
get b get a
Deadlock!!
Perlu Rb dan Ra untuk dieksekusiPerlu Ra dan Rb untuk dieksekusi
![Page 7: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/7.jpg)
Joint ProgressDiagram
1 2
3
4 5
6
![Page 8: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/8.jpg)
Solusi Joint Progress Diagram
Contoh Solusi
Proses P1 dan P2 tidak menggunakan resource pada saat yang bersamaan
P1 P2
Get RaGet Rb
Get RaRelease Ra
Release Rb
Get Rb
Release Ra
Get Ra
![Page 9: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/9.jpg)
Solusi Joint ProgressDiagram (Simulasi)
P1 P2
Ra Rb
release brelease a
release b release aget a get b
get b get a
![Page 10: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/10.jpg)
Solusi Joint Progress Diagram
![Page 11: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/11.jpg)
Reusable Resources
Definisi
Contoh
merupakan resource yang hanya dapat digunakan oleh satu proses sajadalam satu waktu dan tidak pernah habis (selalu tersedia)
Processor I/O Channel Memory
Device Data StructureFile, database, etc
Semaphore
Kasus Deadlock Dua proses berebut menggunakan hardisk atau berebut menggunakan ruang memori
![Page 12: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/12.jpg)
Contoh Deadlock pada Reusable Resources (1)
P1 P2
Eksekusi interleave
Deadlock
![Page 13: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/13.jpg)
Contoh Deadlock pada Reusable Resources (2)Main Memory
(200 KB)
20 KB
20 KB
20 KB
20 KB
20 KB
20 KB
20 KB
20 KB
20 KB
20 KB
P1
...
Request 80 KB
...
Request 60 KB
P2
...
Request 70 KB
...
Request 80 KB
Blockedkurang 10 KB
Blockedkurang 30 KB
Deadlock
![Page 14: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/14.jpg)
Consumable Resources
Definisi
Contoh
Merupakan resource yang dapat dibuat (produced) dandihancurkan (destroyed) berulang-ulang
Interrupt Signal message informasi yang terletak di dalam buffer I/O
Kasus Deadlock Dua proses atau lebih saling menunggu pesan
Sumber deadlock, salah satunya kesalahan perancangan
![Page 15: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/15.jpg)
Contoh Deadlock pada Consumable Resources
P1
...
Receive (P2)
...
Send(P2, M)
P2
...
Receive (P1)
...
Send(P1, M)
Deadlock
waiting
waiting
![Page 16: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/16.jpg)
Resource Allocation Graphs (RAG)
Resource Allocation Graphs (RAG) merupakan grafik berarah yang menggambarkan status resource dan proses dimana setiap proses dan setiapresource digambarkan dengan node
Definisi
GrafikProses Meminta Resource P • Ra
Proses Memegang Resource P • Ra
![Page 17: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/17.jpg)
Representasi Deadlock dengan Resource Allocation Graphs (RAG)
P1 P2
Ra
Ra
Circular Wait
P1 P2
No Deadlock
Ra
Ra
![Page 18: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/18.jpg)
Kondisi Yang MenyebabkanDeadlock (1)
Mutual Exclusion
Hold and Wait
Sebuah resource hanya boleh digunakan oleh sebuah proses dalam satu waktu
Sebuah proses boleh terus menerus menggunakan sebuah resource sambil menunggu resource yang lain
No Preemption Resource yang sedang digunakan oleh suatu proses tidak boleh direbut,Proses tersebut tidak bisa disela (preempted)
Kondisi ini memungkinkan deadlock
Kondisi ini memungkinkan deadlock
Kondisi ini memungkinkan deadlock
![Page 19: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/19.jpg)
Kondisi Yang Menyebabkan Deadlock (2)Bila ketiga kondisi tersebut terdapat di dalam sebuah
komputer apakah pasti terjadi deadlock ?
Merupakan rangkaian beberapa proses danresource yang membentuk sebuah cincin
dimana setiap proses sedang menggunakanminimal sebuah resource yang juga sedang
dibutuhkan oleh proses di dekatnya
P1 P2
Ra
Ra
Belum tentu, kondisi yang memastikan terjadinyaDeadlock adalah ?
Circular Wait
![Page 20: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/20.jpg)
U
Kondisi Yang Menyebabkan Deadlock (3)
P1
P2P3
P4
P1 P2
R1R1
R2
R3
R4P3 P4
R2 R3 R4
![Page 21: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/21.jpg)
Strategi Penanganan Deadlock
Deadlock Prevention
Deadlock Avoidance
Menghilangkan salah satu kondisi atau lebih yang memungkinkan terjadinya deadlock
Dilakukan pemilihan langkah yang dinamis untukmencegah terjadinya deadlock berdasarkan alokasi resource saat itu
Deadlock Detection Mendeteksi adanya kondisi yang memungkinkan deadlock dan circular wait, kemudian melakukan langkah-langkah penanganan
Pada saat perancangan program
Pada saat eksekusi program
Pada saat eksekusi program
![Page 22: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/22.jpg)
1. Definisi dan Konsep Deadlock Prevention
2. Indirect Method
3. Direct Method
Deadlock Prevention
![Page 23: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/23.jpg)
Definisi dan Konsep DeadlockPrevention
Definisi
Indirect Method
Pada saat perancanganmenghilangkan salah satu kondisi atau lebih yang memungkinkan terjadinya deadlock
Sebisa mungkin tidak menggunakan kondisi yang memungkinkan deadlockberikut ini secara bersamaan (mutual exclusion, hold and wait, dan no preemption)
Direct Method Mencegah terjadinya kondisi circular wait
![Page 24: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/24.jpg)
Indirect Method
Mutual Exclusion
Hold & Wait
No Preemption
Tidak bisa dihilangkan, jika terdapat resource yang harus diproteksi
Harus disediakan oleh sistem operasi
setiap proses yang membutuhkan resource akan ter-blok dan baru dapat dieksekusijika semua resource yang diperlukan telah tersedia
Tidak efisien,• Menunggu terlalu lama• Mengeklaim resource yang belum tentu dibutuhkan• Tidak mengetahui resource• Harus mengetahui semua resource
Solusi 1: tetap boleh no preemptionProses yang sedang menggunakan sebuah resource tidak bolehmenggunakan resource yang lain sebelum resource pertama dilepaskan
Solusi 2: PreemptionSistem operasi dapat menyela (preempt) proses yang sedang running sehingga resource yang sedang digunakannya dapat diberikan kepada proses lainSyarat: prioritas proses harus berbeda
![Page 25: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/25.jpg)
Direct Method
Mekanisme
Contoh
Mencegah terjadinya kondisi circular wait,Setiap resource diberi nomor indeks yang terurut secara linier danpenggunaannya harus urut sesuai nomor indeksnya.
Proses A membutuhkan resoure Ri kemudian resource Rj, karena i < j, maka program tersebut benar. Jika program pada proses B terdapat baris program yang membutuhkan resource Rjdiikuti dengan resource Ribisa terjadi deadlock. Kesalahan ada pada proses B karena j > i, seharusnya i < j.
KekuranganTidak efisien, lambat.Terdapat resource yang sedang tidak digunakan tetapi tidak dapat dipakai
![Page 26: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/26.jpg)
1. Konsep Deadlock Avoidance
2. Prosess Initiation Denial3. Resources Allocation Denial
4. Kelebihan dan Kekurangan
Deadlock Avoidance
![Page 27: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/27.jpg)
Konsep Deadlock Avoidance
Konsep
Langkah-langkah
Tidak mempertimbangkan ketiga kondisiyang memungkinkan terjadinya deadlock
1. Cari informasi kebutuhan resource untuk setiap proses
2. Block proses yang menyebabkan deadlock
3. Jangan berikan resource baru kepada proses yang menyebabkan deadlock
Mekanisme Process Initiation Denial
Resource Allocation Denial
![Page 28: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/28.jpg)
Process Initiation Denial (Konsep)
= Σ 𝑃P1
R1
P2 P3 P4 Pn
R2 R3 Rm
. . . . . .
. . . . . .= Σ 𝑅
= Σ 𝑉
![Page 29: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/29.jpg)
Process Initiation Denial (Claim Resource)
Daftar Claim Resource = C = C11 C21 Cn1 C33 C43 Cn3
nmnn
m
m
CCC
CCC
CCC
CClaim
21
22221
11211
Claim proses ke n terhadap resource ke m
![Page 30: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/30.jpg)
Process Initiation Denial (Daftar Alokasi Resource)
Daftar Alocation Resource A = A11 A21 An1 A33 A43 An3
nmnn
m
m
AAA
AAA
AAA
AAllocation
21
22221
11211
Alokasi resource ke mterhadap proses ke n
![Page 31: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/31.jpg)
Process Initiation Denial (Aturan)
n
i
ijjj AVR1
untuk semua j
jij RC untuk semua i,j
ijij CA untuk semua i,j
Rumusan dan aturan
![Page 32: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/32.jpg)
Process Initiation Denial (Claim Proses Baru)
Proses baru (Pn+1) dapat dieksekusi jika kondisi berikut terpenuhi:
untuk semua j
jumlah resource yang diklaim olehproses baru
jumlah resource yang telahdiklaim oleh proses-proses sebelumnya
𝐶 𝑛+1 𝑗
𝑖=1
𝑛
𝐶𝑖𝑗+≥𝑅𝑗
![Page 33: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/33.jpg)
Resource Allocation Denial (konsep)
Menggunakan algoritma banker (seperti model peminjamanuang pada bank)
State (status) Sistem
Safe State
Unsafe State
alokasi sejumlah resource kepada suatu proses saat ini
kondisi dimana setiap saat setidaknya terdapatsebuah proses yang dapat dieksekusi,sehingga seluruh proses dapat dieksekusi hingga selesai
kondisi dimana semua proses tidak dapat dieksekusi (deadlock)
![Page 34: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/34.jpg)
Resource Allocation Denial (Contoh kasus – Initial State)
R1 R2 R3
P1 3 2 2
P2 6 1 3
P3 3 1 4
P4 4 2 2
R1 R2 R3
P1 1 0 0
P2 6 1 2
P3 2 1 1
P4 0 0 2
R1 R2 R3
P1 2 2 2
P2 0 0 1
P3 1 0 3
P4 4 2 0
R1 R2 R3
9 3 6
R1 R2 R3
0 1 1
Initial State
Total resource
Daftar Claim (C) Daftar Alokasi (A) Kekurangan = C-A
Resource tersedia
![Page 35: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/35.jpg)
Resource Allocation Denial (Contoh kasus – Execution State)
R1 R2 R3
P1 3 2 2
P2 6 1 3
P3 3 1 4
P4 4 2 2
R1 R2 R3
P1 1 0 0
P2 6 1 2
P3 2 1 1
P4 0 0 2
R1 R2 R3
P1 2 2 2
P2 0 0 1
P3 1 0 3
P4 4 2 0
R1 R2 R3
9 3 6
R1 R2 R3
0 1 1Total resource
Daftar Claim (C) Daftar Alokasi (A) Kekurangan = C-A
Resource tersedia
-P1 terblok
P2 tidak terblok
![Page 36: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/36.jpg)
R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 3 2 2 1 0 0 2 2 2 0 1 1 -2 -1 -1 Blocked 1 0 0 6 2 3
P2 6 1 3 6 1 2 0 0 1 0 1 1 0 1 0 Pilih 6 1 3 6 2 3
P3 3 1 4 2 1 1 1 0 3 0 1 1 -1 1 -2 Blocked 2 1 1 6 2 3
P4 4 2 2 0 0 2 4 2 0 0 1 1 -4 -1 1 Blocked 0 0 2 6 2 3
P1 3 2 2 1 0 0 2 2 2 6 2 3 4 0 1 Pilih 3 2 2 7 2 3
P2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Selesai 0 0 0 0 0 0
P3 3 1 4 2 1 1 1 0 3 6 2 3 5 2 0 Blocked 2 1 1 7 2 3
P4 4 2 2 0 0 2 4 2 0 6 2 3 2 0 3 Blocked 0 0 2 7 2 3
Proses Resource
No
1
2
Ekse
kusi
Status Akhir
Avalaible Resource
(Vt+1)
Status
ProsesClaim (C) Alokasi (A) C-A (K) Avalaible (Vt) V-K
Status Akhir
Alokasi Proses
Resource Allocation Denial (Contoh kasus – Execution State (1))
R1 R2 R3
9 3 6
Resource Total
Kebutuhan resource Proses yang harus dipenuhiuntuk dapat dieksekusi
Jumlah Resource yang sudahdimiliki/dipegang oleh proses
Jumlah resource yang harus
didapatkan agar memenuhi Claim (C)
Jumlah resource yangtidak dipegang proses
Proses terpilih karenakebutuhan resourcedapat dipenuhi olehresource yang tersedia
Jumlah resource yang dimilikioleh proses yang terpilih/dieksekusi
Jumlah resource yang tersediasetelah proses selesai dieksekusiVt+1 =Vt+C
Pada eksekusike 2P2 sudah selesai dieksekusi
Jumlah resource yang tersedia pada eksekusi ke 2diupdate sesuai dengan status akhir avalaible resource (Vt+1)
P1 dipilihsesuai dengan waktu kedatangan
![Page 37: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/37.jpg)
R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Selesai 0 0 0 0 0 0
P2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Selesai 0 0 0 0 0 0
P3 3 1 4 2 1 1 1 0 3 7 2 3 6 2 0 Pilih 3 1 4 9 3 4
P4 4 2 2 0 0 2 4 2 0 7 2 3 3 0 3 Blocked 0 0 2 9 3 4
P1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Selesai 0 0 0 0 0 0
P2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Selesai 0 0 0 0 0 0
P3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Selesai 0 0 0 0 0 0
P4 4 2 2 0 0 2 4 2 0 9 3 4 5 1 4 Pilih 4 2 2 9 3 6
Status
Proses
Status Akhir
Alokasi Proses
Status Akhir
Avalaible Resource
(Vt+1)NoClaim (C) Alokasi (A) C-A (K) Avalaible (Vt) V-K
3
4
Ekse
kusi
Proses Resource
Resource Allocation Denial (Contoh kasus – Execution State (2))
R1 R2 R3
9 3 6
Resource Total Jumlah resource akhir avalaibleresource HARUS SAMA dengan Total Resource
![Page 38: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/38.jpg)
R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 3 2 2 2 0 1 1 2 1 0 1 1 -1 -1 0 Blocked 1 0 0 6 2 3
P2 6 1 3 5 1 1 1 0 2 0 1 1 -1 1 -1 Blocked 5 1 1 4 2 0
P3 3 1 4 2 1 1 1 0 3 0 1 1 -1 1 -2 Blocked 2 1 1 6 2 3
P4 4 2 2 0 0 2 4 2 0 0 1 1 -4 -1 1 Blocked 0 0 2 6 2 3
Proses Resource
No
1
Ekse
kusi
Status Akhir
Avalaible Resource
(Vt+1)
Status
ProsesClaim (C) Alokasi (A) C-A (K) Avalaible (Vt) V-K
Status Akhir
Alokasi Proses
Resource Allocation Denial (Contoh kasus – Execution State (1))
R1 R2 R3
9 3 6
Resource Total Permintaan proses terhadapresource (C-K) lebih besar dibandingkan resource yang tersedia (Vt)
![Page 39: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/39.jpg)
Contoh Algoritma Deadlock Avoidance
Proses meminta resource
Valid?
blocked
Resourceyang
tersedia cukup?
Berikan resourcedan perbaharui
data
Permintaan safe
error
valid
Tidak valid
cukup
Tidak cukup
Tidak safe
safe
IF alloc [i, *] + request [*] > claim [i, *]THEN error
IF request [*] > claim [i, *]THEN blocked
IF claim [k, *] – alloc [k, *] <= currentavailTHEN safe
Banker algorithmResource alloc algoritm
![Page 40: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/40.jpg)
Contoh Algoritma Deadlock Avoidance (Global Data Structure)
Global Data Structure
![Page 41: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/41.jpg)
Contoh Algoritma Deadlock Avoidance (Resource AllocationAlgorithm)
#41Sistem Operasi/20101103
Resource allocation algoritm
Cek valid atau tidak?
Cek resource cukup atau tidak?
Cek kondisi safe atau tidak
![Page 42: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/42.jpg)
Contoh Algoritma Deadlock Avoidance (Banker Algorithm)
Pengecekkan kondisi safe atau tidak?
![Page 43: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/43.jpg)
Kelebihan dan Kekurangan Deadlock Avoidance
Kelebihan
Kekurangan
(+) Tidak perlu mem-preempt dan mengembalikan data konteks suatu proses
(-) Jumlah kebutuhan resource maksimum setiap proses harus sudah diketahui di awal
(+) Lebih fleksibel dibanding metode deadlock prevention
(-) Urutan eksekusi proses tidak dapat ditentukan dengan aturan tertentu
(-) Jumlah resource yang dialokasikan ke suatu proses bersifat tetap (tidak boleh berubah)
(-) Proses tidak boleh keluar (exit) selama masih memegang resource
![Page 44: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/44.jpg)
1. Mekanisme Deadlock Detection
2. Algoritma Deadlock Detection
3. Contoh Deadlock Detection
4. Solusi Jika Terjadi Deadlock
Deadlock Detection
![Page 45: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/45.jpg)
Mekanisme Deadlock Detection
Setiap Proses boleh meminta resource selama resource masih tersedia
Setiap periodik Sistem Operasi menjalankan algoritma untuk mendeteksi deadlock
Proses-proses yang tidak menyebabkan deadlock akan diberikan tanda (mark)
Menggunakan matrik Alokasi (A), Vektor Avalaible (V), Vektor Resource (R)
Menggunakan matrik request (Q), berisi daftar resource yang diminta oleh Proses
![Page 46: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/46.jpg)
Algoritma Deadlock Detection
#46Sistem Operasi/20101103
Beri tanda (mark) proses yang nilai alokasi (A) = 0.
Inisialisasi temporari vektor W dengan nilai vektor alokasi (A). W = A
Jika nilai Q ≤ W, beri tanda proses tersebut. Tambahkan alokasi (A) ke W𝑊𝑘 = 𝑊𝑘 + 𝐴𝑖𝑘
Cari proses ke i yang belum diberi tanda. Bandingkan nilai request proses tersebut (Q) dengan vektor W.𝑄𝑖𝑗 ≤ 𝑊𝑘, untuk 1 ≤ k ≤ m. Jika tidak ditemukan, terminasi algoritma
Lanjutkan pencarian hingga seluruh proses diperiksa.
![Page 47: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/47.jpg)
Contoh Deadlock Detection
#47Sistem Operasi/20101103
1. Beri tanda (mark) P4. 2. Inisialisasi temporari vektor W dengan nilai vektor alokasi (A). W = (0 0 0 0 1)
3. P1 dan P2 tidak diberi tanda, karena𝑄𝑖𝑗 > 𝑊𝑘. Terminasi algoritma.
Deadlock terdeteksi
![Page 48: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/48.jpg)
Solusi Jika Terjadi Deadlock
#48Sistem Operasi/20101103
Batalkan (kill) semua proses yang mengalami deadlock
Kembalikan status proses tersebut ke status checkpoint yang telah dibuat sebelumnya(sebelum terjadi deadlock)
Restart proses tersebut
Satu per satu batalkan proses lain yang mengalami deadlock hingga tidak ada lagi proses yang deadlock
Satu per satu ambil (preempt) resource dari proses yang mengalami deadlockhingga deadlock tidak terjadi lagi
![Page 49: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/49.jpg)
Solusi Jika Terjadi Deadlock (pemilihan proses yang dibatalkan)
#49Sistem Operasi/20101103
Biaya proses yang paling murah
Paling sedikit menggunakan waktu prosesor
Paling sedikit memberikan hasil
Membutuhkan waktu eksekusi paling lama
Paling sedikit mendapatkan resource
Prioritas terendah
![Page 50: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/50.jpg)
Perbandingan Metode Penanganan Deadlock
![Page 51: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/51.jpg)
1. Deskripsi Masalah
2. Solusi Dengan Semaphore
3. Solusi Dengan Monitor
Kasus Dining Philosopher
![Page 52: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/52.jpg)
Deskripsi Masalah Dining Philosophers
1. Terdapat 5 ahli filsafat
3. Setiap ahli filsafat membutuhkan2 garpu untuk makan spaghetti
4. Ketika seluruh ahli filsafat makanbersamaan akan terjadiDEADLOCK
5. Bagaimana agar tidak terjadideadlock ketika ahli filsafatmakan bersama?
2. Terdapat meja makan bundardengan 5 piring dan 5 garpu
![Page 53: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/53.jpg)
Solusi untuk Dining Philosophers
#53Sistem Operasi/20101103
Membeli 5 buah garpu tambahanMengajari ahli filsafat makan dengan satu garpu
Ada pelayan yang bertugas menyuapi ahli filsafat
Ada pelayan yang bertugas mengawasi ruangan, agar dalam satu waktu hanya ada 4 ahli filsafat yang makan
Semaphore
![Page 54: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/54.jpg)
Masalah Dining Philosophers (Semaphore)
Mendapatkan garpu di tangan kanan
Mendapatkan garpu di tangan kiri
Melepaskan garpu di tangan kiri
Melepaskan garpu di tangan kiri
Critical section
Memungkinkan terjadinya deadlock dan starvation
![Page 55: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/55.jpg)
Masalah Dining Philosophers (Semaphore room)
Terdapat semaphore untukmengakses ruangan (room)untuk menjamin hanya 4 orangyang berada di ruang makan
![Page 56: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/56.jpg)
Masalah Dining Philosophers (monitor)
Cari Informasi implementasi monitor untuk permasalahandining philosopher
![Page 57: 6. Konkurensi_deadlock & starvation (pert 9 & 10)](https://reader030.vdocuments.us/reader030/viewer/2022013115/559426531a28ab45768b4785/html5/thumbnails/57.jpg)
Referensi
[STA09] Stallings, William. 2009. Operating System: Internal and Design Principles. 6th edition. Prentice Hall