Vous êtes sur la page 1sur 2

ASSIGNMENT-1

Q) Simulate the functioning of Lamport's Logical Clock in C.


#include<stdio.h>
#include<conio.h>
long P1(int);
long P2(int);
long P3(int);
long P4(int);
void main()
{
int k;
clrscr();
printf("Enter process no.");
scanf("5d", &k);
while(!*bhi+())
{
if(k==1)
P1(1);
if(k==2)
P2(1);
if(k==3)
P3(1);
if(k==4)
P4(1);
}
getch();
printf("\n Logical Clock \n \n");
printf("P1: %d \n P2: %d \n P3: %d \n P4: %d \n", P1(0), P2(0), P3(0), P4(0));
getch();
}
long P1(int i)
{
static long a=0;
if(i==1)
{
a++;
P2(1);
return(1);
}
else return a;
}

long P2(int i)
{
static long b=0;
if(i==1)
{
p+=;
P3(1);
P4(1);
return 1;
}
else return b;
}
long P3(int i)
{
static long c=0;
if(i==1)
{
C++;
return 1;
else
return(j)
}
long P4(int i)
{
static long d=0;
if(i==1)
{
d++;
P3(1);
return 1;
}
else
return d;
}
OUTPUT:
Enter process no. 1
Logical Clock
P1: 1096396
P2: 1096396
P3: 2192792
P4: 1096396

Vous aimerez peut-être aussi