20CS02002 20CS01014 20CS01061 CC Assignment
20CS02002 20CS01014 20CS01061 CC Assignment
20CS02002 20CS01014 20CS01061 CC Assignment
Assignment
By Thadicherla Hrishith(20CS02002)
Mallela Sathvik(20CS01061)
P.R.R Sumiran Adithya(20CS01014)
Project Statement:
The project requires implementation of Lamport’s Mutual exclusion
using logical clock. The project has to be implemented via sockets
because you need to communicate between 3 devices. The critical
section can be assumed to be access to a file on any one of the 3
machines. There need to be two threads per device. One thread shall
create local event and send event; the send event should only be for
mutual exclusion request. The other thread need to act as port listener
and hence, receiver thread. The only catch here is to synchronise
between sender and receiver thread to update the logical clock. The
implementation needs to be done only in C++ or Java.
Approach to Solution:
The first part of this problem is to create the sender and listener
threads. My approach to this was that don’t need to keep the sender
thread always on. We can just create the sender thread whenever are
are making the request and just send it to the 2 other clients. However
the listener thread needs to be active all the time. So we activate it
when we first take in the ip and port.
The second part of this problem is how do we access the file hosted
on one system from another system.
That’s pretty much the end of our issues outside the logic of the
algorithm . All we need to do is see the issues inside Lamport’s
Mutual Exclusion.
Executing the critical section: Site S, enters the CS when the two
following conditions hold.
[L1:] S_{i} has received a message with timestamp larger than
(ts_{i}, i) from all other sites.
3. Site S_{i} upon exiting the CS, removes its request from the top
of its request queue and sends a timestamped RELEASE message
to all the sites in its request set.
When a site removes a request from its request queue, its own
request may come at the top of the queue, enabling it to enter the
CS. The algorithm executes CS requests in the increasing
order of timestamps.
After this the logic is pretty straight forward and explained in the code
comments.
The above example is of 6000 giving request first and 6001 giving
immediate request next.
Here is a screenshot of timestamps of all the events that happened: