Académique Documents
Professionnel Documents
Culture Documents
KRISHNA VINAY
201501222
I implemented the ricart-agrawala algorithm in java using java RMIs and message passing by
google protobuf and generalised vector clocks.
Ricart-agrawala algorithm:-
This is one of the many algorithms to satisfy mutual exclusion on a distributed system.
We should ensure that one processor must enter critical section at a particular instant or time.
So to satisfy that, we have so many algorithms to ensure this. One of those algorithms are
Ricart-agrawala algorithm.
Here mutex ensures that in every node file, it locks a particular piece of code once. ( cant
access a variable in two different functions once.)
Implementation details:-
After initializations, we have to start RMI server for this node with a fixed name.
Internal Functions:-
After initializations node wants to enter into the critical section thus it calls for lock() and
changes needed_lock = true;
i) Lock()
So, Here Lock functions calls to Lock_request function all other N-1 processors to give
access to enter the critical section and make wait_count=N-1;
Here the message is serialized through google protobuf and it send to desired process in
protobuf format only. Message is just {my_id,my_clock}
And here In the need_ack hash_table it pushes all the processors which it has to receive
the lock to enter CS.
Here, function calling of other nodes is through RMI. It just gets the remote object and calls
lock_request.
After it sends all requests, it waits for acknowledgment from all the processes.
After, that it waits until wait_cont == 0 and after it gets access ti enter into critical section it
changes in_critical_section = true;
And executes critical section
Next it calls unlock function:-
ii) unLock():-
It just sends the acknowledgments to all the processors which are in queue stating that i am
done with my critical section execution.
It sends the id and clock in protobuf format only.
It just sends to all the processors which are in queue.
** Also there are some extra functions which handles the serialization part of a message and
deserialization one. Ex:- getbute()
Anaylisis:-
Ricart-Agrawala algorithm needs 2(N-1) messages for a node to enter into the critical section.
So, Here our code also needs 2*(N-1) messages for every node to enter into critical section. For
every node a file outputs its results into a individual file. And finally, when a node enter into the
critical section, log file goes to output file. This algorithm is completely distributed and
decentralized. But it still requires O(n). If we leave our code after started without interrupting,
every node tries to enter critical section 100 times.