title: Little Book of Semaphores - barrier
body: <p>I'm going through the book mentioned in the topic, and one thing bugs me. For Barrier, the solution is the following (pseudo)code:</p>
  
  <pre><code>1 rendezvous
  2
  3 mutex.wait ()
  4     count = count + 1
  5 mutex.signal()
  6
  7 if count == n: barrier.signal ()
  8
  9  barrier.wait()
  10 barrier.signal()
  11
  12 critical point
  </code></pre>
  
  <p>However, should not the counter's readout be also mutex-protected, so there are no inconsistencies while reading? I mean this:</p>
  
  <pre><code>3 mutex.wait ()
  4     count = count + 1
  5     if count == n: barrier.signal()
  6 mutex.signal()
  </code></pre>
  
  <p>Or am I overly cautious about the counter var maybe?</p>
  
  <p>Thank you for answers.</p>