title: C++ Macs OS X semaphore.h: trouble with `sem_open()` and `sem_wait()`
body: <pre><code>#include &lt;semaphore.h&gt;
  
  sem_t* x;
  
  int main () 
  {
      x = sem_open("x", O_CREAT, 0, 0);;
      sem_wait(x); sem_wait(x); sem_wait(x);
      std::cout &lt;&lt; "\ndone\n";
  }
  </code></pre>
  
  <p>This code shouldn't even pass the first <code>sem_wait()</code> but on my system it reaches the end of <code>main()</code>. Everything I have read, such as <a href="https://stackoverflow.com/questions/1413785/sem-init-on-os-x/1452182#1452182">here</a> and <a href="https://stackoverflow.com/questions/2752085/c-semaphores-sem-wait-throwing-inexplicable-error/2752182#2752182">here</a>, say that, although Mac OS X does not support <code>sem_init()</code>, it does support <code>sem_open()</code>. However, using <code>sem_open()</code> as above hasn't fixed the problem. I'm running OS X 10.5.7.</p>