SlideShare a Scribd company logo
1 of 63
1
Concurrency: Deadlock and
Starvation
Chapter 6
2
Agenda:
• Two problems that affects all efforts to support
concurrent processing:
– Deadlock and Starvation
• Principles of deadlock
• Related problem of starvation
• Common approaches to dealing with deadlock
Prevention ,Detection, Avoidance
• Classic problems used to illustrate both
synchronization and deadlock issues:
– The dining philosophers problem.
• Note: Consideration of concurrency and deadlock on a
single system.
3
Deadlock
• What???
• Permanent blocking of a set of processes that either
compete for system resources or communicate with
each other.
• Deadlock is permanent.
• What to do when ……
– No efficient solution
– Deadlocks involve Involve conflicting needs for
resources by two or more processes
4
5
• Different execution paths:
• 1. Q acquires B and then A and then releases B and A. When P
resumes execution, it will be able to acquire both resources.
• 2. Q acquires B and then A. P executes and blocks on a request for
A. Q releases B and A. When P resumes execution, it will be able to
acquire both resources.
• 3. Q acquires B and then P acquires A. Deadlock is inevitable,
because as execution proceeds, Q will block on A and P will block
on B.
• 4. P acquires A and then Q acquires B. Deadlock is inevitable,
because as execution proceeds, Q will block on A and P will block
on B.
• 5. P acquires A and then B. Q executes and blocks on a request for
B. P releases A and B. When Q resumes execution, it will be able to
acquire both resources.
• 6. P acquires A and then B and then releases A and B. When Q
resumes execution, it will be able to acquire both resources. 6
7
8
Reusable Resources
• Used by only one process at a time and not
depleted by that use
• Processes obtain resources that they later
release for reuse by other processes
• Processors, I/O channels, main and secondary
memory, devices, and data structures such as
files, databases, and semaphores
• Deadlock occurs if each process holds one
resource and requests the other
9
Example of Deadlock
10
Another Example of Deadlock
• Space is available for allocation of
200Kbytes, and the following sequence
of events occur
• Deadlock occurs if both processes
progress to their second request
P1
. . .
. . .
Request 80 Kbytes;
Request 60 Kbytes;
P2
. . .
. . .
Request 70 Kbytes;
Request 80 Kbytes;
11
Consumable Resources
• Created (produced) and destroyed
(consumed)
• Interrupts, signals, messages, and
information in I/O buffers
• Deadlock may occur if a Receive
message is blocking
• May take a rare combination of events to
cause deadlock
12
Example of Deadlock
• Deadlock occurs if receive is blocking
P1
. . .
. . .
Receive(P2);
Send(P2, M1);
P2
. . .
. . .
Receive(P1);
Send(P1, M2);
13
Resource Allocation Graphs
• Directed graph that depicts a state of the
system of resources and processes
14
Resource Allocation Graphs
15
Conditions for Deadlock
• When????
• Mutual exclusion
– Only one process may use a resource at a
time
• Hold-and-wait
– A process may hold allocated resources
while awaiting assignment of others
• No preemption
– No resource can be forcibly removed form a
process holding it
16
Conditions for Deadlock
• Circular wait
– A closed chain of processes exists, such that each
process holds at least one resource needed by the
next process in the chain
17
18
Possibility of Deadlock
• Mutual Exclusion
• No preemption
• Hold and wait
19
Existence of Deadlock
• Mutual Exclusion
• No preemption
• Hold and wait
• Circular wait
20
Deadlock Prevention
• Mutual Exclusion
– Must be supported by the operating system
• Hold and Wait
– Require a process request all of its required
resources at one time
21
Deadlock Prevention
– Prob:
– Process may be held up for a long time waiting for
all of its resource requests to be filled, when in fact
it could have proceeded with only some of the
resources.
– Resources allocated to a process may remain
unused for a considerable period, during which
time they are denied to other processes.
– A process may not know in advance all of the
resources that it will require.
22
Deadlock Prevention
• No Preemption
– Process must release resource and request
again
– Operating system may preempt a process to
require it releases its resources
• Circular Wait
– Define a linear ordering of resource types
23
Deadlock Avoidance
• A decision is made dynamically whether
the current resource allocation request
will, if granted, potentially lead to a
deadlock
• Requires knowledge of future process
request
24
Two Approaches to
Deadlock Avoidance
• Do not start a process if its demands
might lead to deadlock
• Do not grant an incremental resource
request to a process if this allocation
might lead to deadlock
25
Resource Allocation Denial
• Referred to as the banker’s algorithm
• State of the system is the current
allocation of resources to process
• Safe state is where there is at least one
sequence that does not result in deadlock
• Unsafe state is a state that is not safe
26
Resource Allocation Denial
27
Determination of a Safe State
Initial State
• Can any of the four processes be run to
completion with the resources available?
28
29
Determination of a Safe State
P2 Runs to Completion
30
Determination of a Safe State
P1 Runs to Completion
31
Determination of a Safe State
P3 Runs to Completion
following deadlock avoidance strategy,
ensures that the system of processes and
resources is always in a safe state.
32
33
Determination of an
Unsafe State
34
Determination of an
Unsafe State
• The deadlock avoidance strategy does
not predict deadlock with certainty;
• It merely anticipates the possibility of
deadlock and assures that there is never
such a possibility
35
36
Deadlock Avoidance Logic
37
Deadlock Avoidance Logic
38
Deadlock Avoidance
• Adv.
– Less restrictive than prevention strategy.
• Limitations:
– Maximum resource requirement must be stated in
advance
– Processes under consideration must be
independent; no synchronization requirements
– There must be a fixed number of resources to
allocate
– No process may exit while holding resources
39
Deadlock Detection
• Deadlock prevention strategies are conservative
• They solve the problem of deadlock by limiting
access to resources and by imposing restrictions
on processes.
• Deadlock detection strategies do not limit resource
• access or restrict process actions.
• Deadlock detection, requested resources are
granted to processes whenever possible.
• Periodically, the OS performs an algorithm that
allows it to detect the circular wait condition
described earlier in condition.
40
Deadlock Detection
• Frequency of checking????
– each resource request OR
– depending on how likely it is for a deadlock to occur.
• Adv 1st
– It leads to early detection,
– The algorithm is relatively simple because it is
based on incremental changes to the state of the
system.
• Disadv:
– frequent checks consume considerable processor
time.
41
Deadlock Detection
• The algorithm proceeds by marking processes that are not
deadlocked.
• Initially, all processes are unmarked.
Deadlock Detection Algorithm
1. Mark each process that has a row in the allocation matrix of
all zeros
2. Initialize a temporary vector W to equal to available vector.
3. Find an index i such that process i is currently unmarked and
the ith row of request matrix is less than or equal to W.
• If no such row is found, terminate the algorithm and
all unmarked processes are those involved in the
deadlock.
4. If such a row is found, mark process i and add the
corresponding row of the allocation matrix to W. Return to
step 3
Deadlock Detection Algorithm
• A deadlock exists if and only if there are
unmarked processes at the end of the algorithm.
• Each unmarked process is deadlocked.
• Algorithm does not guarantee to prevent deadlock
• All that it does is determine if deadlock currently
exists.
44
Strategies once Deadlock
Detected
• Abort all deadlocked processes
• Back up each deadlocked process to some
previously defined checkpoint, and restart all
process
– Original deadlock may occur
• Successively abort deadlocked processes
until deadlock no longer exists
• Successively preempt resources until
deadlock no longer exists
45
Selection Criteria Deadlocked
Processes
• Least amount of processor time consumed so
far
• Least number of lines of output produced so
far
• Most estimated time remaining
• Least total resources allocated so far
• Lowest priority
46
Strengths and Weaknesses of the
Strategies
47
Dining Philosophers Problem
48
Dining Philosophers Problem
49
Dining Philosophers Problem
50
Dining Philosophers Problem
51
Dining Philosophers Problem
Exercise
52
53
UNIX Concurrency
Mechanisms
• Pipes
• Messages
• Shared memory
• Semaphores
• Signals
54
55
Linux Kernel Concurrency
Mechanisms
• Includes all the mechanisms found in
UNIX
• Atomic operations execute without
interruption and without interference
56
Linux Atomic Operations
57
Linux Atomic Operations
58
Linux Kernel Concurrency
Mechanisms
• Spinlocks
– Used for protecting a critical section
59
60
Linux Kernel Concurrency
Mechanisms
61
Solaris Thread
Synchronization Primitives
• Mutual exclusion (mutex) locks
• Semaphores
• Multiple readers, single writer
(readers/writer) locks
• Condition variables
62
63

More Related Content

Similar to Chapter06.ppt

3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].pptamadayshwan
 
DEADLOCK PREVENTION AND AVOIDANCE.pptx
DEADLOCK PREVENTION AND AVOIDANCE.pptxDEADLOCK PREVENTION AND AVOIDANCE.pptx
DEADLOCK PREVENTION AND AVOIDANCE.pptxPugalenthiSomasundar
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptxsheraz7288
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserMatthew Chang
 
The Functions of the Operating System
The Functions of the Operating SystemThe Functions of the Operating System
The Functions of the Operating Systemandyr91
 
4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptxDishaDwivedi2
 
Lecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptxLecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptxAmanuelmergia
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptxJOHNZHOU52
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptxshrijanasharma3
 

Similar to Chapter06.ppt (20)

Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt
 
DEADLOCK PREVENTION AND AVOIDANCE.pptx
DEADLOCK PREVENTION AND AVOIDANCE.pptxDEADLOCK PREVENTION AND AVOIDANCE.pptx
DEADLOCK PREVENTION AND AVOIDANCE.pptx
 
Chapter06
Chapter06Chapter06
Chapter06
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parser
 
OS 7.pptx
OS 7.pptxOS 7.pptx
OS 7.pptx
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
The Functions of the Operating System
The Functions of the Operating SystemThe Functions of the Operating System
The Functions of the Operating System
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
Deadlock 4.pptx
Deadlock 4.pptxDeadlock 4.pptx
Deadlock 4.pptx
 
Deadlocks Part- III.pdf
Deadlocks Part- III.pdfDeadlocks Part- III.pdf
Deadlocks Part- III.pdf
 
Distributed Deadlock Detection.ppt
Distributed Deadlock Detection.pptDistributed Deadlock Detection.ppt
Distributed Deadlock Detection.ppt
 
deadlock.ppt
deadlock.pptdeadlock.ppt
deadlock.ppt
 
4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx
 
Lecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptxLecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptx
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptx
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 

Recently uploaded

Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 

Chapter06.ppt

  • 2. 2 Agenda: • Two problems that affects all efforts to support concurrent processing: – Deadlock and Starvation • Principles of deadlock • Related problem of starvation • Common approaches to dealing with deadlock Prevention ,Detection, Avoidance • Classic problems used to illustrate both synchronization and deadlock issues: – The dining philosophers problem. • Note: Consideration of concurrency and deadlock on a single system.
  • 3. 3 Deadlock • What??? • Permanent blocking of a set of processes that either compete for system resources or communicate with each other. • Deadlock is permanent. • What to do when …… – No efficient solution – Deadlocks involve Involve conflicting needs for resources by two or more processes
  • 4. 4
  • 5. 5
  • 6. • Different execution paths: • 1. Q acquires B and then A and then releases B and A. When P resumes execution, it will be able to acquire both resources. • 2. Q acquires B and then A. P executes and blocks on a request for A. Q releases B and A. When P resumes execution, it will be able to acquire both resources. • 3. Q acquires B and then P acquires A. Deadlock is inevitable, because as execution proceeds, Q will block on A and P will block on B. • 4. P acquires A and then Q acquires B. Deadlock is inevitable, because as execution proceeds, Q will block on A and P will block on B. • 5. P acquires A and then B. Q executes and blocks on a request for B. P releases A and B. When Q resumes execution, it will be able to acquire both resources. • 6. P acquires A and then B and then releases A and B. When Q resumes execution, it will be able to acquire both resources. 6
  • 7. 7
  • 8. 8 Reusable Resources • Used by only one process at a time and not depleted by that use • Processes obtain resources that they later release for reuse by other processes • Processors, I/O channels, main and secondary memory, devices, and data structures such as files, databases, and semaphores • Deadlock occurs if each process holds one resource and requests the other
  • 10. 10 Another Example of Deadlock • Space is available for allocation of 200Kbytes, and the following sequence of events occur • Deadlock occurs if both processes progress to their second request P1 . . . . . . Request 80 Kbytes; Request 60 Kbytes; P2 . . . . . . Request 70 Kbytes; Request 80 Kbytes;
  • 11. 11 Consumable Resources • Created (produced) and destroyed (consumed) • Interrupts, signals, messages, and information in I/O buffers • Deadlock may occur if a Receive message is blocking • May take a rare combination of events to cause deadlock
  • 12. 12 Example of Deadlock • Deadlock occurs if receive is blocking P1 . . . . . . Receive(P2); Send(P2, M1); P2 . . . . . . Receive(P1); Send(P1, M2);
  • 13. 13 Resource Allocation Graphs • Directed graph that depicts a state of the system of resources and processes
  • 15. 15 Conditions for Deadlock • When???? • Mutual exclusion – Only one process may use a resource at a time • Hold-and-wait – A process may hold allocated resources while awaiting assignment of others • No preemption – No resource can be forcibly removed form a process holding it
  • 16. 16 Conditions for Deadlock • Circular wait – A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain
  • 17. 17
  • 18. 18 Possibility of Deadlock • Mutual Exclusion • No preemption • Hold and wait
  • 19. 19 Existence of Deadlock • Mutual Exclusion • No preemption • Hold and wait • Circular wait
  • 20. 20 Deadlock Prevention • Mutual Exclusion – Must be supported by the operating system • Hold and Wait – Require a process request all of its required resources at one time
  • 21. 21 Deadlock Prevention – Prob: – Process may be held up for a long time waiting for all of its resource requests to be filled, when in fact it could have proceeded with only some of the resources. – Resources allocated to a process may remain unused for a considerable period, during which time they are denied to other processes. – A process may not know in advance all of the resources that it will require.
  • 22. 22 Deadlock Prevention • No Preemption – Process must release resource and request again – Operating system may preempt a process to require it releases its resources • Circular Wait – Define a linear ordering of resource types
  • 23. 23 Deadlock Avoidance • A decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock • Requires knowledge of future process request
  • 24. 24 Two Approaches to Deadlock Avoidance • Do not start a process if its demands might lead to deadlock • Do not grant an incremental resource request to a process if this allocation might lead to deadlock
  • 25. 25 Resource Allocation Denial • Referred to as the banker’s algorithm • State of the system is the current allocation of resources to process • Safe state is where there is at least one sequence that does not result in deadlock • Unsafe state is a state that is not safe
  • 27. 27 Determination of a Safe State Initial State
  • 28. • Can any of the four processes be run to completion with the resources available? 28
  • 29. 29 Determination of a Safe State P2 Runs to Completion
  • 30. 30 Determination of a Safe State P1 Runs to Completion
  • 31. 31 Determination of a Safe State P3 Runs to Completion
  • 32. following deadlock avoidance strategy, ensures that the system of processes and resources is always in a safe state. 32
  • 35. • The deadlock avoidance strategy does not predict deadlock with certainty; • It merely anticipates the possibility of deadlock and assures that there is never such a possibility 35
  • 38. 38 Deadlock Avoidance • Adv. – Less restrictive than prevention strategy. • Limitations: – Maximum resource requirement must be stated in advance – Processes under consideration must be independent; no synchronization requirements – There must be a fixed number of resources to allocate – No process may exit while holding resources
  • 39. 39 Deadlock Detection • Deadlock prevention strategies are conservative • They solve the problem of deadlock by limiting access to resources and by imposing restrictions on processes. • Deadlock detection strategies do not limit resource • access or restrict process actions. • Deadlock detection, requested resources are granted to processes whenever possible. • Periodically, the OS performs an algorithm that allows it to detect the circular wait condition described earlier in condition.
  • 40. 40 Deadlock Detection • Frequency of checking???? – each resource request OR – depending on how likely it is for a deadlock to occur. • Adv 1st – It leads to early detection, – The algorithm is relatively simple because it is based on incremental changes to the state of the system. • Disadv: – frequent checks consume considerable processor time.
  • 41. 41 Deadlock Detection • The algorithm proceeds by marking processes that are not deadlocked. • Initially, all processes are unmarked.
  • 42. Deadlock Detection Algorithm 1. Mark each process that has a row in the allocation matrix of all zeros 2. Initialize a temporary vector W to equal to available vector. 3. Find an index i such that process i is currently unmarked and the ith row of request matrix is less than or equal to W. • If no such row is found, terminate the algorithm and all unmarked processes are those involved in the deadlock. 4. If such a row is found, mark process i and add the corresponding row of the allocation matrix to W. Return to step 3
  • 43. Deadlock Detection Algorithm • A deadlock exists if and only if there are unmarked processes at the end of the algorithm. • Each unmarked process is deadlocked. • Algorithm does not guarantee to prevent deadlock • All that it does is determine if deadlock currently exists.
  • 44. 44 Strategies once Deadlock Detected • Abort all deadlocked processes • Back up each deadlocked process to some previously defined checkpoint, and restart all process – Original deadlock may occur • Successively abort deadlocked processes until deadlock no longer exists • Successively preempt resources until deadlock no longer exists
  • 45. 45 Selection Criteria Deadlocked Processes • Least amount of processor time consumed so far • Least number of lines of output produced so far • Most estimated time remaining • Least total resources allocated so far • Lowest priority
  • 46. 46 Strengths and Weaknesses of the Strategies
  • 53. 53 UNIX Concurrency Mechanisms • Pipes • Messages • Shared memory • Semaphores • Signals
  • 54. 54
  • 55. 55 Linux Kernel Concurrency Mechanisms • Includes all the mechanisms found in UNIX • Atomic operations execute without interruption and without interference
  • 58. 58 Linux Kernel Concurrency Mechanisms • Spinlocks – Used for protecting a critical section
  • 59. 59
  • 61. 61 Solaris Thread Synchronization Primitives • Mutual exclusion (mutex) locks • Semaphores • Multiple readers, single writer (readers/writer) locks • Condition variables
  • 62. 62
  • 63. 63