l8: deadlocks - academia cartagena99l8: deadlocks este texto se distribuye bajo los t erminos de la...
TRANSCRIPT
![Page 1: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/1.jpg)
1
L8: Deadlocks
Este texto se distribuye bajo los terminos de la Creative Commons License
Cesar Sanchez
Grado en Ingenierıa InformaticaGrado en Matematicas e Informatica
Universidad Politecnica de Madrid
Fri, 27 Feb 2015
Underco
nstruct
ion! Donot prin
t
![Page 2: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/2.jpg)
2
Mapa Conceptual
Concurrency = Simultaneous + Nondeterminism + Interaction
Interaction = Communication | Synchronization
Synchronization = Mutual Exclusion | ConditionalSynchronization
atomic race conditioninterleaving busy-waitmutual exclusion critical sectiondeadlock livelockliveness
Terminology:
![Page 3: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/3.jpg)
3
Deadlock
Deadlock:
a deadlock is a situation in which two or more competing actionsare each waiting for the other to finish, and thus neither everdoes.
![Page 4: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/4.jpg)
3
Deadlock
Deadlock:
a deadlock is a situation in which two or more competing actionsare each waiting for the other to finish, and thus neither everdoes.
“When two trains approach each other at a crossing, both shallcome to a full stop and neither shall start up again until the otherhas gone.”
Statute passed by the Kansas State Legislature,early in the 20th century.
![Page 5: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/5.jpg)
4
Livelock
Livelock:
A livelock is similar to a deadlock, except that the states of theprocesses involved in the livelock constantly change with regardto one another, none progressing.
![Page 6: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/6.jpg)
4
Livelock
Livelock:
A livelock is similar to a deadlock, except that the states of theprocesses involved in the livelock constantly change with regardto one another, none progressing.
![Page 7: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/7.jpg)
5
Conditions for Deadlock (necessary and sufficient)
1. Mutual Exclusion
The resource is only accessed by one thread at a time.
2. Hold and wait
The resource is kept until the job is finished.
3. No preemption
A resource is not stolen.
4. Circular wait
There is a circular chain of processes waiting for resources heldby the next process in the chain.
![Page 8: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/8.jpg)
6
Resource allocation graph
R1
R2
P
Q
![Page 9: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/9.jpg)
6
Resource allocation graph
R1
R2
P
Q
![Page 10: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/10.jpg)
6
Resource allocation graph
R1
R2
P
Q
![Page 11: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/11.jpg)
6
Resource allocation graph
R1
R2
P
Q
![Page 12: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/12.jpg)
6
Resource allocation graph
R1
R2
P
Q
![Page 13: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/13.jpg)
7
Resource allocation graph (Deadlock Example)
R1
R2
P
Q
![Page 14: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/14.jpg)
7
Resource allocation graph (Deadlock Example)
R1
R2
P
Q
![Page 15: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/15.jpg)
7
Resource allocation graph (Deadlock Example)
R1
R2
P
Q
![Page 16: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/16.jpg)
7
Resource allocation graph (Deadlock Example)
R1
R2
P
Q
![Page 17: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/17.jpg)
7
Resource allocation graph (Deadlock Example)
R1
R2
P
Q
![Page 18: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/18.jpg)
7
Resource allocation graph (Deadlock Example)
R1
R2
P
Q
![Page 19: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/19.jpg)
7
Resource allocation graph (Deadlock Example)
R1
R2
P
Q
![Page 20: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/20.jpg)
8
Deadlock.java
public void run () {
for (int n = 1; n <= Dining.ROUNDS; ++ n) {
//think();
left.take();
System.out.println(me+" takes fork "+left.me);
right.take();
System.out.println(me+" takes fork "+right.me);
eat();
right.put_back();
left.put_back();
}
System.out.println(me+" leaves");
}
![Page 21: L8: Deadlocks - Academia Cartagena99L8: Deadlocks Este texto se distribuye bajo los t erminos de la Creative Commons License C esar S anchez Grado en Ingenier a Inform atica Grado](https://reader034.vdocuments.net/reader034/viewer/2022050119/5f4fdc5c61a8d86f5c5ce7b7/html5/thumbnails/21.jpg)
9
Starvation
Starvation:
Starvation describes a situation where a thread is unable to gainregular access to shared resources and is unable to make progress.This happens when shared resources are made unavailable for longperiods by “greedy” threads.