9
Logical Clocks (addendum)

Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Embed Size (px)

Citation preview

Page 1: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Logical Clocks (addendum)

Page 2: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Logical Clocks

In the class of Feb 3 the question was asked about having different numbers for different events.

Page 3: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Example 1

Assume that P3 has a loop that is executed n times. At the termination of the loop a message is sent to P1. The value of n is arbitrary. A part of P3’s code could look something like this:3.1: i = 0;

3.2: while (i < n)

3.3: i = i+1;

3.4: send (i,P2);

Assume that n = 2; The timing diagram would look something like what appears on the next page.

Page 4: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Example 1

a

b

P1 P2 P3

c

d

e

f

g

h

i

j

p

j is the event that statement 3.1 executes; k is the event that 3.2executes; l is the event that 3.3 executes; m is the event that 3.2 executes; n is the event that 3.3 executes; o is the event that 3.2 executes;p is the event that statement 3.4 executes

k

l

m

1 12

3

4

3

8

9

10

l

n

2345

7

6o

Page 5: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Example 1

a

b

P1 P2 P3

c

d

e

f

g

h

i

j

Assume n is 1 instead of 2. Event j is associated with statement 3.1;Event k is associated with statement 3.2; Event l is associated withStatement 3.3; Event m is associated with statement 3.2; Event n is associatedwith statement 3.4

k

l

m

1 12

3

4

3

6

7

8

l

n

2345

Page 6: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Example 2 In the previous examples we had statements like

“recv(x, P3)” – basically it was made explicit where a message was to be received from.

However, this doesn’t have to be the case. Essentially we can have “recv(x,?)” where the process is waiting for any process.

Assume that P2 has a code segment that looks like the following:3.1: while(;;) {3.2: recv(x,?);3.3 Process message}

P1 and P3 are processes that send messages to P2.

Page 7: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Example

a

b

P1 P2 P3

c

d

e

f

g

ij

m

n

o

Event e represents the execution of 3.1; Event f represents the execution of 3.2; event g represents the execution of event 3.3; event h represents the execution of 3.1; event i represents the execution of 3.2; event j represents the execution of 3.3; event k represents the execution of 3.1;Event l represents the execution of 3.2

1 112

3503

4 4

5152

51h 5

kl

5354

Lots of processing;Assume that k is 50

Page 8: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Example

P1 may be on a much faster machine then P3 and so both its messages may arrive at P2 before P3’s messages

Page 9: Logical Clocks (addendum). Logical Clocks In the class of Feb 3 the question was asked about having different numbers for different events

Example

a

b

P1 P2 P3

c

d

e

f

g

ij

j

k

l

Event e represents the execution of 3.1; Event f represents the execution of 3.2; event g represents the execution of event 3.3; event h represents the execution of 3.1; event i represents the execution of 3.2; event j represents the execution of 3.3; event k represents the execution of 3.1;Event l represents the execution of 3.2

1 112

3503

4 4

67

51h

kl

851

5