What is Concurrency? Expain with example Deadlock and
Starvation?
Answer Posted / manoj
Deadlocks and Starvation
Readings: Chapter on Deadlocks in Tanenbaum. You can skip
Deadlock
Detection and Banker’s Algorithm.
· We looked at solving synchronization problems using
monitors and
semaphores.
· Unfortunately, problems can arise
Example 1:
Recall our solution to the reader-writer problem. It was
possible for
readers to wait indefinitely if new writers kept coming in.
On the other hand, writers would not wait indefinitely as
long as ready
threads are served in order.
Why?Thread A Thread B
lock(x)
lock(y)
Use resource X and Y
Unlock(y)
Unlock(x)
Lock(y)
Lock(x)
Use resource X and Y
Unlock(x)
Unlock(y)
In this case, it is possible that both Thread A and Thread B
wait
indefinitely for each other, with no progress being made.
What is common and different between the above examples?
Common aspect: Both problems involve threads waiting for
resources to
become available. They can also involve
· Resources: things needed by a thread to do its job a
thread *waits*
for resources
o e.g., locks, AW+WW = 0 (i.e., database is free from active or
waiting writers), disk blocks, memory pages
· Indefinite wait: In both examples, a thread may end up waiting
indefinitely.
Differences between the two examples: The type of waiting is
different.
· Starvation
A thread may wait indefinitely because other threads keep coming
in and getting the requested resources before this thread
does. Note that
resource is being actively used and the thread will stop
waiting if other
threads stop coming in.
· Deadlocks
A group of threads are waiting for resources held by others
in the
group. None of them will ever make progress.
Example 1 has starvation, but Example 2 does not.
A solution to a synchronization problem suffers from the
starvation
problem if starvation is a possibility. Usually, differences
in priorities can
lead to starvation. Lower priority threads starve if higher
priority threads
keep requesting the resources.
A solution suffers from the deadlock problem if a deadlock
is a possibility.
In Example 2, will a deadlock always occur?
| Is This Answer Correct ? | 1 Yes | 4 No |
Post New Answer View All Answers
What are the operating system types?
How much ram can you put in a 64 bit system?
What are the 4 stages of computing?
What are necessary conditions which can lead to a deadlock situation in a system?
Describe horizontal scalability and vertical scalability.
What is the Difference between a process and a thread?
Explain the concept of real-time operating systems?
What is a full form of ok?
Is 100 cpu usage bad?
Do I need 32gb of ram?
How can I tell if a program is 64 bit?
What items of information about a task might be useful in real time scheduling?
What are the different states of a process?
How often should I run chkdsk?
what is the command to copy windows files (i386) without formatting OS?