Does the following algorithm solve the mutual exclusion problem? Discuss your answer based on the requirements for
the solutions of the mutual exclusion problem, as discussed in the lecture.

Requirements for Mutual Exclusion:

Give an example execution for the ring-based algorithm to the mutual exclusion problem showing that processes are not necessarily granted entry to the critical section in the happened-before order.
The processes in the ring-based algorithm are granted entry to the critical section in the order they are arranged on the ring. For example if the process situated counter-clockwise right next to the process holding the token is requesting access to the critical section and while the token is being passed, another process is also requesting access, by the time the token gets to the second requesting process, this one will get access although it requested it later (cf. Figure 2.1).

A distributed system may have multiple, independent critical sections. Suppose that Process Pi wants to enter critical section A and Process Pj wants to enter critical section B. Can Ricart and Agrawala’s algorithm lead to deadlock? Explain your answer.
It depends on the ground rules. If processes access resources strictly sequentially, that is, a process holding a resource may not attempt to access another one, then there is no way that it can block while holding a resource that some other process wants. The system is then deadlock free. On the other hand, if process Pi is allowed to access resource A and then try to access resource B, a deadlock can occur if some other process tries to acquire them in the reverse order. The Ricart and Agrawala algorithm is only designed for accessing a single resource.
(a) For leader election, assume that two processes detect the demise of the coordinator simultaneously and both decide to hold an election using the Bully algorithm. What happens?
Solution: Bully algorithm at a glance:

(b) Adapt the Bully algorithm to deal with temporary network partitions and slow processes.