title: Using Semaphores to ensure order
body: <p>Suppose that there is a game where three players move, and each player is given a color (R,G,B). Is there a way to ensure that the players move in the order R then G then B using only semaphores, if three routines must be made (one for each player's move)? (Assuming that R will always start).</p>
  
  <p>This question is not supposed to take into account any special type of semaphores that might be found in a particular programming language, instead it should just be a textbook semaphore.</p>
  
  <p>My proposed solution was (in pseudo code):</p>
  
  <pre><code>Red {
       wait(R)
       wait(B)
       wait(G)
            Move Red
       signal(G)
       signal(B)
       signal(R)
  }
  
  Blue {
       wait(R)
       wait(B)
       wait(G)
            Move Blue
       signal(G)
       signal(B)
       signal(R)
  }
  
  Green {
       wait(R)
       wait(B)
       wait(G)
            Move Green
       signal(G)
       signal(B)
       signal(R)
  }
  </code></pre>
  
  <p>But I don't think this works because while Red is guaranteed to go first, then we don't know that Blue is going to get the B semaphore before Green gets it; or even that Blue will get the R semaphore before Green gets it.</p>
  
  <p>Is there another way to do this? Am I missing something?</p>