title: POSIX semaphore upper limit
body: <p>I am looking into utilizing semaphores as classic counter. It would have a starting value of 5, which could go down to 0, but could not go above 5.</p>
  
  <pre><code>sem_t sem;
  sem_init(&amp;sem, 0, 5);
  
  // ...
  
  sem_wait(&amp;sem); // goes down to 4
  
  //...
  
  sem_post(&amp;sem); // goes up to 5
  sem_post(&amp;sem); // goes up to 6 ?! 
  </code></pre>
  
  <p>I went thought the docs, but I don't see any <code>sem_post</code>-like function which does just that. Now, I know this behavior could implemented with mutex and int, but I was kind of interested if similar thing could be done this way (a bit less of code).</p>