1/ Does the algorithm uphold Mutual Exclusion?
2/ Is the algorithm free from deadlock and is starvation possible?
I can't seem to get my head around deadlock. I do believe there is no mutual exclusion as any client can enter the critical section?
Thanks
This is an algorithm where clients request a "lock" that is granted by a server.
This indeed is a mutual exclusion algorithm. Assume to the contrary that two client i and j are between
C2andC3. W.l.o.g, say that i was the first one to enter the critical section.When i did so, necessarily
respond = ihad to be true atC1. This had to happen at the server'sQ2.Looking at the server's code, it can't reach
Q2again untilQ3fails, namely untilrespond == 0. Looking at the client's code, this could only happen when i left the critical section atC3.This contradicts j being simultaneously in the critical section -
Q2could only be reached again when i left the critical section, so, before that, it is impossible that j passedC1.The algorithm is not free from starvation. Client j could unlimitedly be untimely bypassed by some client i. The algorithm is free from deadlock: there is only a single critical section, and if any thread entering it will eventually exit it, then it will be eventually available to another thread (albeit possibly the same one).