






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Readings:
(^) Chapter on Deadlocks in Tanenbaum. You can skip Deadlock
Unfortunately, problems can arise
Example 2: Why?threads are served in order.On the other hand, writers would not wait indefinitely as long as readyreaders to wait indefinitely if new writers kept coming in.Recall our solution to the reader-writer problem. It was possible forExample 1:
Thread A
Thread B
Unlock(x)Unlock(y)Use resource X and Ylock(y) lock(x)
Unlock(y)Unlock(x)Use resource X and YLock(x)Lock(y)
Common aspect: What is common and different between the above examples?indefinitely for each other, with no progress being made. In this case, it is possible that both Thread A and Thread B wait
(^) 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
o for resources waiting writers), disk blocks, memory pagese.g., locks, AW+WW = 0 (i.e., database is free from active or
Indefinite wait:
(^) In both examples, a thread may end up waiting
indefinitely.
Differences between the two examples:
(^) The type of waiting is different.
o Raise priority if a thread has been waiting too long.
o Use FIFO order among competing requests
Preventing deadlocks:
To understand how to prevent deadlocks, one must figure out
necessary conditions for a deadlock to occur. There are four necessary
condition fails, then you cannot have a deadlock.conditions, all of which must hold, for a deadlock to occur. If any one 1) there's no waiting. i.e., not enough to serve all threads simultaneously. Otherwise Limited (shared) resource
No preemption:
(^) Preemption means you forcefully take away the
resource from someone. (Hard to do that with locks.)
Hold and wait:
(^) Threads in a deadlock hold a resource, and wait for
another resource
Circular wait:
o thread A is waiting for resource y
o resource y is held by thread B
o thread B is waiting for resource x
o resource x is held by thread A
The above is called a
(^) wait-for
(^) graph
someone else wants to switch from EECS 482 to EECS 484 :-)
Example #4: Deadlock always leads to starvation (but not necessarily vice versa)The shared resources in this case is spot in the two classes.Both of you are waiting for each other to drop the course, will wait forever(don't want to drop the old course and not be able to add the new course)To switch, you want to add the new course, then drop the old course
(^) dining philosophers
each philosopher needs two chopsticks to eatchopsticks total)5 philosphers sitting around a round table, 1 chopstick in between each (5^ (This is a classic problem, also due to Dijkstra) Algorithm for philosopher:
put both chopsticks downeatwait for left chopstick to be free, then pick it upwait for right chopstick to be free, then pick it up
Can this deadlock? If so, how?
undo the firing of a missile?Not always possible to roll back a thread. E.g., how do you
Basic idea is to get rid of one of the 4 necessary conditions Deadlock prevention (and avoidance):
have full classes, but unlikelymake it very unlikely. E.g., large classrooms. Still possible toEven if you can't make it so deadlock is impossible, you can
Dining Philosophers:reduce the number of threads competing for them.Sometimes, if you cannot make resources unlimited, you can
switch, get back to it later)can preempt CPU (save its state in its thread control block and
back latercan preempt memory, e.g., by saving it to disk and loading it
can't preempt the holding of a lock
of a critical section.is dangerous to preempt locks. A thread may be in the middleUsually not applicable to synchronization problems because it
California, you get a busy signal.E.g., phone company. If it can't get all the lines needed to callEliminate hold: if can't satisfy resource right away, thread dies.
Example 2?Time-out requests for each lock and retry? Will this work in still held. This is sometime called aThis is just another form of waiting if some resources are
(^) livelock
way, giving up all the held resources, and retry.On a time-out, threads must be prepared to back out all the
could be viewed as undoing its recent actions)chopstick. If the other is busy, drop the one you grabbed. Thisbeginning. E.g., grab both chopsticks at same time (or grab oneEliminate wait while holding: Request all resources at o all resources at beginningmany resources need. Inefficient, because it reserveshard to predict the future. Tend to overestimate how
Circular chain of requests Impose an ordering between resources and ensure that you
always request resources in order.