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 C2
and C3
. W.l.o.g, say that i was the first one to enter the critical section.
When i did so, necessarily respond = i
had to be true at C1
. This had to happen at the server's Q2
.
Looking at the server's code, it can't reach Q2
again until Q3
fails, namely until respond == 0
. Looking at the client's code, this could only happen when i left the critical section at C3
.
This contradicts j being simultaneously in the critical section - Q2
could only be reached again when i left the critical section, so, before that, it is impossible that j passed C1
.
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).