Homework 9

22C:116, Fall 1999

Due Friday Nov 5, 1999, in class

Douglas W. Jones

  1. Background Consider a token-ring distributed mutual exclusion algorithm, using an agent process to handle token forwarding, as follows:
    	variables shared between a user process and its agent
    	  state, either wants-in or idle
    	  user-sem and agent-sem, local semaphores, initially 0
    
    	agent
    	  repeat
    	    await token
    	    forward token
    	    if state = wants-in
    	      signal user-sem
    	      wait agent-sem
    	    endif
    	  forever
    
    	enter-cs
    	  state = wants-in
    	  wait user-sem
    	  await token
    
    	exit-cs
    	  state = idle
    	  signal agent-sem
    	  forward token
    
    Assume that the token takes at most "cycle" seconds to circulate around the ring, even if each and every user on the ring enters the critical section and holds the token for as long as possible. Assume that "await token or timeout after time n" is an available option. Assume that "send token(m)" and "await token(m)" are allowed, where m is a message attached to the token.

    Part A: Write detailed pseudocode for a replacement version of this code that will survive the loss of a token by regenerating exactly one token. Assume all processes continue to run and the only error that interests you is loss of a token on a communications link around the ring.

    Part B: What UNIX service provides the equivalent of "await token(m) or timeout after time n"? (There is such a service. It is an afterthought. It was added along with the socket mechanism when network support was added to UNIX).

  2. A Question: Suggest pseudocode for clock synchronization using the primitives outlined above for message passing around a ring of machines. Do not worry about fault tolerance, but pay close attention to the impact of the ring topology and to the fact that machines around the ring each add information to the message being circulated as they pass it onward.