Program 2 Lamport'S Logical Clock: Consistency Condition, Which Is Two Way (If
Program 2 Lamport'S Logical Clock: Consistency Condition, Which Is Two Way (If
A Lamport clock may be used to create a partial causal ordering of events between processes.
Given a logical clock following these rules, the following relation is true: if then
, where means happened-before.
This relation only goes one way, and is called clock consistency condition: if one event comes
before another, then that event's logical clock comes before the others. The strong clock
consistency condition, which is two way (if then ), can be obtained by
other techniques such as vector clocks. Using only a simple Lamport clock, only a partial causal
ordering can be inferred from the clock.
However, via the contra positive, it's true that implies . So, for example,
if then cannot have happened-before .
Another way of putting this is that means that may have happened-before ,
or be incomparable within the happened-before ordering, but did not happen after .
Nevertheless, Lamport timestamps can be used to create a total ordering of events in a distributed
system by using some arbitrary mechanism to break ties (e.g. the ID of the process). The caveat
is that this ordering is art factual and cannot be depended on to imply a causal relationship.
Two implementation rules for implementing Lamport’s Logical Clock are as follow:
IR1:-
IR1 says that a clock Ci incremented between any two successive events in process P i by the
formula
Ci=Ci+d. d>0
IR2:-
IR2 states that if event ‘a’ is a message sending event from process Pi then this message is
assigned a time stamp Tm=Ci(a). On receiving that message by process Pj, Cj is updated
according to the formula
Cj=MAX(Tm+d,Cj) d>0
Program:-
#include<stdio.h>
void main()
int p1[10],p2[10],i,j,n=0,m=0;
clrscr();
{
p1[i]=i;
printf("\n%d",p1[i]);
}
p2[j]=j;
printf("\n%d",p2[j]);
}
scanf("%d",&m);
p2[m]=max(p1[n]+1,p2[m]);
printf("\nthe new timestamp for p2..");
for(j=1;j<=10;j++)
if(j>m)
{
p2[j]=p2[m]+1;
m++;
}
printf("\n%d",p2[j]);
}
}
OUTPUT