inp = raw_input(CLIENT_PROMPT) except EOFError: break sinput = inp.split() cmd = sinput[0] # Supported commands - enter | exit # Use `enter` to acquire the distributed lock before entering the critical # section. The process will wait until the lock is available. # Once acquired, the distributed lock can be released with the `exit` command # If the process does not own the distributed lock, this will be a no-op if cmd == 'enter': print "Waiting for mutex lock..." # Multicast request to all processes in its group cs_request = RCOMessage(mp.local_name, "", "MCAST_CS_REQUEST", mp.local_name) mp.co_multicast(cs_request) # Wait until lock is acquired lock_acquired_event.wait() print "Inside critical section. Type exit to quit." elif cmd == 'exit': if lock_acquired: print "Leaving critical section. Releasing mutex lock now." lock_acquired = False lock_acquired_event.clear() acks_received = 0 # Multicast release to all processes in its group cs_release = RCOMessage(mp.local_name, "", "MCAST_CS_RELEASE", mp.local_name) mp.co_multicast(cs_release) else: print "Umm... You are not in a critical section..." else: