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
Do you know what is a binary semaphore?
How can you check whether a machine is 64 bit or 32 bit?
Is 64gb ram enough for gaming?
What are old chkdsk files?
What layer is http?
How can I make usb bootable?
Explain the stipulations of c2 level security?
What is the maximum ram for a 64 bit operating system?
What is the unified memory architecture? Explain.
What first program that the computer runs when the power is turn on?
Explain how a TP Monitor manages memory and processor resources more effectively than a typical operating system.
Hello this is gaurav garg I have completed BCA. plz TEll me how will ask question in interview.
What is the purpose of system calls?
Describe system calls and its type
What items of information about a task might be useful in real time scheduling?