SlideShare a Scribd company logo
1 of 15
Running head: DEADLOCK, PREVENTION & LOGICAL CLOCKS 1 (Ver 1.00)
Unit 4 Individual Project
Deadlock, Deadlock Prevention & Logical Clocks
ThienSi (TS) Le
Colorado Technical University
CS 844-1503C-01: Concurrent & Distributed Systems
Professor: Dr. Bo Sanden
August 30, 2015
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 2
Title
Deadlock, Deadlock Prevention & Logical Clocks
This Unit 4 Individual Project (U4 IP) provides a short review of simultaneous
exclusive access to multiple resources in the entity-life modeling (ELM) (Sandén, 2015).
It focuses on deadlock issue in concurrent and distributed computer systems. For
example, the simplest deadlock or circular wait is when one entity holds a resource 1
while waiting indefinitely for a resource 2 and another entity holds the resource 2 while
waiting indefinitely for the resource 1. This paper discusses the deadlock, its deadlock
prevention, and logical clocks such as a vector clock, happened-before relation, and
partial order rule (Sandén, 2011).
The U4 IP consists of five sections and a reference section as shown below:
Part 1: The diagram of wait chain.
Refer Appendix Section Part 1 for detailed information.
Given a program in pseudo code with two threads and six resources, develop a
wait-chain diagram then answer four following scenarios:
1. There are only instances of T. How many T instances does it take to create
deadlock?
2. There are only instances of U. How many U instances does it take to create
deadlock?
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 3
3. There are many instances of T and some instances of U. How many Us does it
take to create a deadlock? How many Ts need to participate in the circular wait
4. Assuming that each U thread needs exclusive access to C+D together at one point,
C+E at another point, and D+E at a third point. Give an example of an order rule that
allows this but prevents deadlock. (U may have to be restructured to comply with the
rule.)
Part 2: The diagram of the vector clocks
Refer Appendix Section Part 2 for detailed information.
Given a partial diagram of vector clocks below, determine the timestamp of each
event occurrence.
Part 3: The before relation.
The happens-before relation is a partial order. So is the order rule you used as one
approach for deadlock prevention. What does it mean that the order is only partial? Do
not only quote a formal definition. Use an example to illustrate if you wish.
Part 4: Summary
This section consists of a brief summary of solutions or responses to the given
issues or problems of the parts 1, 2, and 3.
Part 5: Appendix
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 4
This section simply contains the detailed responses on the given issues or problems
of the Parts 1, 2, and 3. Parts 4 and 5 are a summary and appendix.
A. PART 1: Wait-chain diagram.
Given a program in pseudo code with two threads T, U and six resources A
through F, the wait-chain diagram can be developed as follows:
Logic Code
Thread T: A,B,C,E,F: Resources Thread U: C,D,E: Resources
Segment I A.Acquire; Segment III E.Acquire;
B.Acquire; C.Acquire;
A.Release; E.Release;
C.Acquire; Segment IV D.Acquire;
B.Release; C.Release;
C.Release; E.Acquire;
Segment II E.Acquire; E.Release;
F.Acquire; D.Release;
A.Acquire;
A.Release;
F.Release;
E.Release;
The wait-chain diagram consists of four segments:
a. Segment I:
- An instance 1 of thread type T holds 1 resource A while it waits for 1 resource B.
- During another instance, say instance 2, of thread type T, holds the resource B
and waits for a resource C.
- Then all resources A, B, and C are released.
- Segment I is shown in the diagram: A -> B -> C
b. Segment II:
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 5
- The third instance of thread type T holds both resources E and E in the box while
waiting for A as shown in the diagram: (E, F) -> A
c. Segment III:
- An instance of thread type U holds a resource E while waiting for resource C as
shown in the diagram: E -> C
d. Segment IV:
- During the second instance U holds C (from the previous segment III), it waits for
resource D.
- The third instance of thread type U holds resource D and waits for resource E as
shown in the diagram C -> D -> E
The Timeline displays how thread instances hold and wait for the resources A, B ,
C ,D , E, and F in the bold segments. The resources A through F, that are held and
waited, are located above the Time Line. The resources A through F that are released and
denoted as A- through F-, are relased and located below the Time Line. For example, in
the segment I of the time line diagram, the resources (e.g., denoted A, C) are held
sequentially and they (e.g., denoted A-, C-) are released at different time later.
Diagram 1:
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 6
Question 1: There are only instances of T. How many T instances does it take to
create deadlock?
Answer 1: If there are only instances of T, the diagram 2 below shows that we need at
least 5 instances of T to create a deadlock in a big outer loop (A, B, C, D, E, F, A). Note
the instance of T in the box (E, F) is not counted.
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 7
2. There are only instances of U. How many U instances does it take to create
deadlock?
If there are the only instances of U, we need exactly three instances of U for a
deadlock as shown in a right loop in the diagram 4 below:
Diagram 4:
3. There are many instances of T and some instances of U. How many Us does it take
to create a deadlock? How many Ts need to participate in the circular wait.
With the diagram 5 below:
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 8
The right-hand side loop shows that a deadlock can be created with exactly three
instances of U’s.
For a circular wait as shown in diagram 5, a deadlock can be created with 3 T’s
and 2 U’s in the outer loop. The instance U of E -> C and instance T of E -> F in the box
are not taken into account because they are not needed.
4. Assuming that each U thread needs exclusive access to C+D together at one point,
C+E at another point, and D+E at a third point. Give an example of an order rule that
allows this but prevents deadlock. (U may have to be restructured to comply with the
rule.)
The scenario (i.e., each U thread needs exclusive access to C+D together at one
point, C+E at another point, and D+E at a third point) does not create a deadlock in the
resource order: C < D < E and C < E such that each thread holds a lesser resource and
waits for a greater one in the static locking order as shown in diagram 6.
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 9
For example, there is no deadlock in this situation below:
Three banking tellers 1, 2, 3 hold and wait to access three client checking
accounts A, B, C in this order:
- Teller 1 holds account A and waits to access account B.
- Teller 2 holds account B and waits to access account C.
- Teller 3 holds account A and waits to access account C.
Another scenario is each U thread needs exclusive access to C+D together at one
point, D+E at another point, and E+C at a third point. There will be a deadlock because
the static locking order rule is violated. The tread U holds E while it waits for the lesser
resource C as shown in diagram 7:
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 10
B. PART 2: Diagram of vector clocks.
With vector clocks rules of incrementing its own timestamp and selecting the
maximum position value(s) of the receiving message timestamp and its own timestamp,
the complete vector clocks diagram is shown as follows:
Notice that all current vector clock values are greater the previous vector clock
values. In other words, the vector clock timestamps are always incremented along the
timeline.
C. PART 3: The happened-before relation.
According to Lamport (1978), a logical clock is used to control the order of event
occurrences such that all threads are synchronized properly in a distributed computer
system. The happened-before relation of two event occurrences (a, b) is a binary relation
when an event a occurs either before or after another event b in that order – but not both
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 11
and not at the same time. The happened-before relation of two event occurrences (a, b) is
denoted: a -> b. For example, a booking for a ticket reservation in an airline reservation
system should be granted if it is made before the flight is filled. The event occurrences in
the happened-before relation are simply similar to someone who wants to add a garage to
his house; first he needs to get a permit from the city hall.
The happened-before relation is usually partially ordering in logical clocks
(Fidge, 1991). Partial order of event occurrences means that not every pairs of event
occurrences are related in the happened-before situation. For example, the highway I-95
from Providence, RI to Boston, MA has many highway segments that branch to other
cities and towns such as Walpole, Norwood, Stoughton, Randolph, Braintree, Quincy,
Dorchester, and Boston.
- A motorist may take two highway segments Walpole - Norwood and Norwood –
Stoughton to destination Stoughton.
- Another motorist may take two highway segments Walpole - Norwood and Norwood
– Randolph to his destination Randolph.
These highway segments (e.g., Walpole – Norwood, Norwood – Stoughton,
Norwood – Randolph) are partially ordered because a motorist who wants to go to
Stoughton does not need to take a highway segment Norwood – Randolph.
However, a motorist, who wants to go from Providence to Boston, takes the entire
groups of highway segments (Providence to Boston) on I-95 to bypass Walpole,
Norwood, Stoughton, Randolph, Braintree, Quincy, Dorchester. In this case, this is a
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 12
total order relation because every segment of the highway is needed and in order from
the beginning Providence to the farthest destination Boston.
Another example is International Logan Airport in Boston. The main highway I-
93 to the airport has many segment branches to go to airline terminals A, B, C. D, and E.
A lot of passengers can take either segment to the desirable terminal for the airlines that
take them to the proper destinations. Since a passenger must take a certain road segment
to wanted airline gate, the segments of terminals are partially ordered. If he or she wants
to take a road segment to terminal A, he or she must not take other segments that go to
other terminal B, C, D, or E.
In concurrent and distributed system, event occurrences or message
communications such as transmitting (TX) and receiving (RV) messages are partially
ordered because the nodes are randomly transmit message to other nodes and receive
messages from other nodes. The number of nodes may usually be mixed such that some
nodes transmit messages, other nodes receive messages. It is impossible to have a
distributed system with a total order happened-before relation because of characteristic
nature of the nodes in the network.
D. SUMMARY
This paper discusses the deadlock, its deadlock prevention, and logical clocks
such as a vector clock, happens-before relation, and partial order. The document consists
of five sections as listed above and explains the concepts with eight illustrated diagrams
and many practical examples in concurrent and distributed networking computer system.
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 13
E. APPENDIX
Unit 4 - Individual Project
Type: Individual Project
Unit: Deadlock Prevention and Logical Clocks
Due Date: Mon, 8/31/15
Grading Type: Numeric
Points Possible: 100
Points Earned: 0
Deliverable Length: 2–3 pages with supporting diagrams
Assignment Objectives
Define deadlock and demonstrate that a simple system is deadlock free.
Describe approaches to deadlock prevention.
Explain the need for logical clocks and show how a basic logical clock works.
Assignment Description
Weekly tasks or assignments (Individual or Group Projects) will be due by Monday, and
late submissions will be assigned a late penalty in accordance with the late penalty policy
found in the syllabus. NOTE: All submission posting times are based on midnight Central
Time.
Part 1: There are 6 resources, A through F, each with the operations Acquire and
Release. Upon return from X. Acquire the calling thread has exclusive access to resource
X. By calling X. Release, the caller releases the exclusive access. There are two thread
types, T and U, with the following logic:
T: A.Acquire; U: E.Acquire;
B.Acquire; C.Acquire;
A.Release; E.Release;
C.Acquire; D.Acquire;
B.Release; C.Release;
C.Release; E.Acquire;
E.Acquire; E.Release;
F.Acquire; D.Release;
A.Acquire;
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 14
A.Release;
F.Release;
E.Release;
Draw a wait-chain diagram. Then consider the following scenarios:
 There are only instances of T. How many T instances does it take to create
deadlock?
 There are only instances of U. How many U instances does it take to create
deadlock?
 There are many instances of T and some instances of U. How many Us does it
take to create a deadlock? How many Ts need to participate in the circular wait?
 Assuming that each U thread needs exclusive access to C+D together at one point,
C+E at another point, and D+E at a third point. Give an example of an order rule
that allows this but prevents deadlock. (U may have to be restructured to comply
with the rule.)
Part 2: What is each node’s (process’s) vector clock value at the end? P1’s clock starts at
(1, 0, 0). P2’s clock starts at (0, 1, 0). P3’s clock starts at (0, 0, 1).
Part 3: The happens-before relation is a partial order. So is the order rule you used as one
approach for deadlock prevention. What does it mean that the order is only partial? Do
not only quote a formal definition. Use an example to illustrate if you wish.
Other Information
Instructions:
For Part 3: To clarify, the question is: What does it mean that the order is only
partial (and not total)?
DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 15
REFERENCES
Fidge, C. (1991). Logical time in distributed computing systems, IEEE Computer, vol.
24, no. 8, pp. 28-33.
Lamport, L. (1978). Time, clocks, and the ordering of events in a distributed
system. Communications of the ACM, 21(7), 558-565.
Sandén, B. I. (2011). Design of multithreaded software: The entity-life modeling
approach. John Wiley & Son.
Sandén, B. (2015). Study guide for CS844 (and CS838) Concurrent and distributed
systems. Study Guide.
Sanden, B. (2015). Live Chat: CS844-1503C-01 – Section D. Distributed Systems.
Retrieved from: Colorado Technical University, Virtual Campus

More Related Content

Similar to CS844 U4 Individual Project

1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx
1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx
1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx
madlynplamondon
 

Similar to CS844 U4 Individual Project (20)

JGrass-NewAge probabilities forward component
JGrass-NewAge probabilities forward component JGrass-NewAge probabilities forward component
JGrass-NewAge probabilities forward component
 
auto correlation.pdf
auto correlation.pdfauto correlation.pdf
auto correlation.pdf
 
1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx
1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx
1ELEG-548 Low Power VLSI Circuit Design, Spring 2020, Ho.docx
 
Modern physics paul a. tipler 6ª edição solutio manual
Modern physics   paul a. tipler 6ª edição solutio manualModern physics   paul a. tipler 6ª edição solutio manual
Modern physics paul a. tipler 6ª edição solutio manual
 
Single fault detection and diagnosis technique for digital micro fluidic base...
Single fault detection and diagnosis technique for digital micro fluidic base...Single fault detection and diagnosis technique for digital micro fluidic base...
Single fault detection and diagnosis technique for digital micro fluidic base...
 
SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...
SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...
SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...
 
SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...
SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...
SINGLE FAULT DETECTION AND DIAGNOSIS TECHNIQUE FOR DIGITAL MICRO-FLUIDIC BASE...
 
Behavioural analysis of a complex manufacturing system having queue in the ma...
Behavioural analysis of a complex manufacturing system having queue in the ma...Behavioural analysis of a complex manufacturing system having queue in the ma...
Behavioural analysis of a complex manufacturing system having queue in the ma...
 
7 web
7 web7 web
7 web
 
Chua's circuit
Chua's circuitChua's circuit
Chua's circuit
 
Characteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-abilityCharacteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-ability
 
Concurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case StudiesConcurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case Studies
 
2nd midterm gla university
2nd midterm gla university2nd midterm gla university
2nd midterm gla university
 
JGrass-NewAge probabilities backward component
JGrass-NewAge probabilities backward component JGrass-NewAge probabilities backward component
JGrass-NewAge probabilities backward component
 
Hidden markov chain and bayes belief networks doctor consortium
Hidden markov chain and bayes belief networks doctor consortiumHidden markov chain and bayes belief networks doctor consortium
Hidden markov chain and bayes belief networks doctor consortium
 
Hidden markov chain and bayes belief networks doctor consortium
Hidden markov chain and bayes belief networks doctor consortiumHidden markov chain and bayes belief networks doctor consortium
Hidden markov chain and bayes belief networks doctor consortium
 
GEOframe-NewAge: documentation for probabilitiesbackward component
GEOframe-NewAge: documentation for probabilitiesbackward componentGEOframe-NewAge: documentation for probabilitiesbackward component
GEOframe-NewAge: documentation for probabilitiesbackward component
 
Queueing Theory.pptx
Queueing Theory.pptxQueueing Theory.pptx
Queueing Theory.pptx
 
Modeling and Reasoning over Declarative Data-Aware Processes
Modeling and Reasoning over Declarative Data-Aware ProcessesModeling and Reasoning over Declarative Data-Aware Processes
Modeling and Reasoning over Declarative Data-Aware Processes
 
Solow1957
Solow1957Solow1957
Solow1957
 

CS844 U4 Individual Project

  • 1. Running head: DEADLOCK, PREVENTION & LOGICAL CLOCKS 1 (Ver 1.00) Unit 4 Individual Project Deadlock, Deadlock Prevention & Logical Clocks ThienSi (TS) Le Colorado Technical University CS 844-1503C-01: Concurrent & Distributed Systems Professor: Dr. Bo Sanden August 30, 2015
  • 2. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 2 Title Deadlock, Deadlock Prevention & Logical Clocks This Unit 4 Individual Project (U4 IP) provides a short review of simultaneous exclusive access to multiple resources in the entity-life modeling (ELM) (Sandén, 2015). It focuses on deadlock issue in concurrent and distributed computer systems. For example, the simplest deadlock or circular wait is when one entity holds a resource 1 while waiting indefinitely for a resource 2 and another entity holds the resource 2 while waiting indefinitely for the resource 1. This paper discusses the deadlock, its deadlock prevention, and logical clocks such as a vector clock, happened-before relation, and partial order rule (Sandén, 2011). The U4 IP consists of five sections and a reference section as shown below: Part 1: The diagram of wait chain. Refer Appendix Section Part 1 for detailed information. Given a program in pseudo code with two threads and six resources, develop a wait-chain diagram then answer four following scenarios: 1. There are only instances of T. How many T instances does it take to create deadlock? 2. There are only instances of U. How many U instances does it take to create deadlock?
  • 3. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 3 3. There are many instances of T and some instances of U. How many Us does it take to create a deadlock? How many Ts need to participate in the circular wait 4. Assuming that each U thread needs exclusive access to C+D together at one point, C+E at another point, and D+E at a third point. Give an example of an order rule that allows this but prevents deadlock. (U may have to be restructured to comply with the rule.) Part 2: The diagram of the vector clocks Refer Appendix Section Part 2 for detailed information. Given a partial diagram of vector clocks below, determine the timestamp of each event occurrence. Part 3: The before relation. The happens-before relation is a partial order. So is the order rule you used as one approach for deadlock prevention. What does it mean that the order is only partial? Do not only quote a formal definition. Use an example to illustrate if you wish. Part 4: Summary This section consists of a brief summary of solutions or responses to the given issues or problems of the parts 1, 2, and 3. Part 5: Appendix
  • 4. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 4 This section simply contains the detailed responses on the given issues or problems of the Parts 1, 2, and 3. Parts 4 and 5 are a summary and appendix. A. PART 1: Wait-chain diagram. Given a program in pseudo code with two threads T, U and six resources A through F, the wait-chain diagram can be developed as follows: Logic Code Thread T: A,B,C,E,F: Resources Thread U: C,D,E: Resources Segment I A.Acquire; Segment III E.Acquire; B.Acquire; C.Acquire; A.Release; E.Release; C.Acquire; Segment IV D.Acquire; B.Release; C.Release; C.Release; E.Acquire; Segment II E.Acquire; E.Release; F.Acquire; D.Release; A.Acquire; A.Release; F.Release; E.Release; The wait-chain diagram consists of four segments: a. Segment I: - An instance 1 of thread type T holds 1 resource A while it waits for 1 resource B. - During another instance, say instance 2, of thread type T, holds the resource B and waits for a resource C. - Then all resources A, B, and C are released. - Segment I is shown in the diagram: A -> B -> C b. Segment II:
  • 5. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 5 - The third instance of thread type T holds both resources E and E in the box while waiting for A as shown in the diagram: (E, F) -> A c. Segment III: - An instance of thread type U holds a resource E while waiting for resource C as shown in the diagram: E -> C d. Segment IV: - During the second instance U holds C (from the previous segment III), it waits for resource D. - The third instance of thread type U holds resource D and waits for resource E as shown in the diagram C -> D -> E The Timeline displays how thread instances hold and wait for the resources A, B , C ,D , E, and F in the bold segments. The resources A through F, that are held and waited, are located above the Time Line. The resources A through F that are released and denoted as A- through F-, are relased and located below the Time Line. For example, in the segment I of the time line diagram, the resources (e.g., denoted A, C) are held sequentially and they (e.g., denoted A-, C-) are released at different time later. Diagram 1:
  • 6. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 6 Question 1: There are only instances of T. How many T instances does it take to create deadlock? Answer 1: If there are only instances of T, the diagram 2 below shows that we need at least 5 instances of T to create a deadlock in a big outer loop (A, B, C, D, E, F, A). Note the instance of T in the box (E, F) is not counted.
  • 7. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 7 2. There are only instances of U. How many U instances does it take to create deadlock? If there are the only instances of U, we need exactly three instances of U for a deadlock as shown in a right loop in the diagram 4 below: Diagram 4: 3. There are many instances of T and some instances of U. How many Us does it take to create a deadlock? How many Ts need to participate in the circular wait. With the diagram 5 below:
  • 8. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 8 The right-hand side loop shows that a deadlock can be created with exactly three instances of U’s. For a circular wait as shown in diagram 5, a deadlock can be created with 3 T’s and 2 U’s in the outer loop. The instance U of E -> C and instance T of E -> F in the box are not taken into account because they are not needed. 4. Assuming that each U thread needs exclusive access to C+D together at one point, C+E at another point, and D+E at a third point. Give an example of an order rule that allows this but prevents deadlock. (U may have to be restructured to comply with the rule.) The scenario (i.e., each U thread needs exclusive access to C+D together at one point, C+E at another point, and D+E at a third point) does not create a deadlock in the resource order: C < D < E and C < E such that each thread holds a lesser resource and waits for a greater one in the static locking order as shown in diagram 6.
  • 9. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 9 For example, there is no deadlock in this situation below: Three banking tellers 1, 2, 3 hold and wait to access three client checking accounts A, B, C in this order: - Teller 1 holds account A and waits to access account B. - Teller 2 holds account B and waits to access account C. - Teller 3 holds account A and waits to access account C. Another scenario is each U thread needs exclusive access to C+D together at one point, D+E at another point, and E+C at a third point. There will be a deadlock because the static locking order rule is violated. The tread U holds E while it waits for the lesser resource C as shown in diagram 7:
  • 10. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 10 B. PART 2: Diagram of vector clocks. With vector clocks rules of incrementing its own timestamp and selecting the maximum position value(s) of the receiving message timestamp and its own timestamp, the complete vector clocks diagram is shown as follows: Notice that all current vector clock values are greater the previous vector clock values. In other words, the vector clock timestamps are always incremented along the timeline. C. PART 3: The happened-before relation. According to Lamport (1978), a logical clock is used to control the order of event occurrences such that all threads are synchronized properly in a distributed computer system. The happened-before relation of two event occurrences (a, b) is a binary relation when an event a occurs either before or after another event b in that order – but not both
  • 11. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 11 and not at the same time. The happened-before relation of two event occurrences (a, b) is denoted: a -> b. For example, a booking for a ticket reservation in an airline reservation system should be granted if it is made before the flight is filled. The event occurrences in the happened-before relation are simply similar to someone who wants to add a garage to his house; first he needs to get a permit from the city hall. The happened-before relation is usually partially ordering in logical clocks (Fidge, 1991). Partial order of event occurrences means that not every pairs of event occurrences are related in the happened-before situation. For example, the highway I-95 from Providence, RI to Boston, MA has many highway segments that branch to other cities and towns such as Walpole, Norwood, Stoughton, Randolph, Braintree, Quincy, Dorchester, and Boston. - A motorist may take two highway segments Walpole - Norwood and Norwood – Stoughton to destination Stoughton. - Another motorist may take two highway segments Walpole - Norwood and Norwood – Randolph to his destination Randolph. These highway segments (e.g., Walpole – Norwood, Norwood – Stoughton, Norwood – Randolph) are partially ordered because a motorist who wants to go to Stoughton does not need to take a highway segment Norwood – Randolph. However, a motorist, who wants to go from Providence to Boston, takes the entire groups of highway segments (Providence to Boston) on I-95 to bypass Walpole, Norwood, Stoughton, Randolph, Braintree, Quincy, Dorchester. In this case, this is a
  • 12. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 12 total order relation because every segment of the highway is needed and in order from the beginning Providence to the farthest destination Boston. Another example is International Logan Airport in Boston. The main highway I- 93 to the airport has many segment branches to go to airline terminals A, B, C. D, and E. A lot of passengers can take either segment to the desirable terminal for the airlines that take them to the proper destinations. Since a passenger must take a certain road segment to wanted airline gate, the segments of terminals are partially ordered. If he or she wants to take a road segment to terminal A, he or she must not take other segments that go to other terminal B, C, D, or E. In concurrent and distributed system, event occurrences or message communications such as transmitting (TX) and receiving (RV) messages are partially ordered because the nodes are randomly transmit message to other nodes and receive messages from other nodes. The number of nodes may usually be mixed such that some nodes transmit messages, other nodes receive messages. It is impossible to have a distributed system with a total order happened-before relation because of characteristic nature of the nodes in the network. D. SUMMARY This paper discusses the deadlock, its deadlock prevention, and logical clocks such as a vector clock, happens-before relation, and partial order. The document consists of five sections as listed above and explains the concepts with eight illustrated diagrams and many practical examples in concurrent and distributed networking computer system.
  • 13. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 13 E. APPENDIX Unit 4 - Individual Project Type: Individual Project Unit: Deadlock Prevention and Logical Clocks Due Date: Mon, 8/31/15 Grading Type: Numeric Points Possible: 100 Points Earned: 0 Deliverable Length: 2–3 pages with supporting diagrams Assignment Objectives Define deadlock and demonstrate that a simple system is deadlock free. Describe approaches to deadlock prevention. Explain the need for logical clocks and show how a basic logical clock works. Assignment Description Weekly tasks or assignments (Individual or Group Projects) will be due by Monday, and late submissions will be assigned a late penalty in accordance with the late penalty policy found in the syllabus. NOTE: All submission posting times are based on midnight Central Time. Part 1: There are 6 resources, A through F, each with the operations Acquire and Release. Upon return from X. Acquire the calling thread has exclusive access to resource X. By calling X. Release, the caller releases the exclusive access. There are two thread types, T and U, with the following logic: T: A.Acquire; U: E.Acquire; B.Acquire; C.Acquire; A.Release; E.Release; C.Acquire; D.Acquire; B.Release; C.Release; C.Release; E.Acquire; E.Acquire; E.Release; F.Acquire; D.Release; A.Acquire;
  • 14. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 14 A.Release; F.Release; E.Release; Draw a wait-chain diagram. Then consider the following scenarios:  There are only instances of T. How many T instances does it take to create deadlock?  There are only instances of U. How many U instances does it take to create deadlock?  There are many instances of T and some instances of U. How many Us does it take to create a deadlock? How many Ts need to participate in the circular wait?  Assuming that each U thread needs exclusive access to C+D together at one point, C+E at another point, and D+E at a third point. Give an example of an order rule that allows this but prevents deadlock. (U may have to be restructured to comply with the rule.) Part 2: What is each node’s (process’s) vector clock value at the end? P1’s clock starts at (1, 0, 0). P2’s clock starts at (0, 1, 0). P3’s clock starts at (0, 0, 1). Part 3: The happens-before relation is a partial order. So is the order rule you used as one approach for deadlock prevention. What does it mean that the order is only partial? Do not only quote a formal definition. Use an example to illustrate if you wish. Other Information Instructions: For Part 3: To clarify, the question is: What does it mean that the order is only partial (and not total)?
  • 15. DEADLOCK, DEADLOCK PREVENTION & LOGICAL CLOCKS 15 REFERENCES Fidge, C. (1991). Logical time in distributed computing systems, IEEE Computer, vol. 24, no. 8, pp. 28-33. Lamport, L. (1978). Time, clocks, and the ordering of events in a distributed system. Communications of the ACM, 21(7), 558-565. Sandén, B. I. (2011). Design of multithreaded software: The entity-life modeling approach. John Wiley & Son. Sandén, B. (2015). Study guide for CS844 (and CS838) Concurrent and distributed systems. Study Guide. Sanden, B. (2015). Live Chat: CS844-1503C-01 – Section D. Distributed Systems. Retrieved from: Colorado Technical University, Virtual Campus