title: Semaphore values in c
body: <p>If I understand correctly, from this post:
  <a href="http://www.csc.villanova.edu/~mdamian/threads/posixsem.html" rel="nofollow">http://www.csc.villanova.edu/~mdamian/threads/posixsem.html</a></p>
  
  <p>Then after each thread passes from sem_wait(&amp;sem1) because of an sem_post(&amp;sem1) from somewhere else, the value of the semaphore should increment.
  So if I do:</p>
  
  <pre><code>    sem_wait(&amp;sem1);
      int sval2;
      if (sem_getvalue(&amp;sem1, &amp;sval2) == 0){
          printf("Semaphore value: %d\n", sval2);
      }   
  </code></pre>
  
  <p>With </p>
  
  <pre><code>sem_init(&amp;sem1, 0, 0);
  </code></pre>
  
  <p>Executed previously, my output should be:</p>
  
  <pre><code>1
  2
  3
  4
  etc......
  </code></pre>
  
  <p>I am asking this, because in my project, the events seem to be following the correct order, but when I do the sem_getvalue, the output on some semaphores stay constant (0), at others goes +1 once, then stays constant (1), and on others it goes up and down (1, then 3, then 4, then 5, then 3, etc...).</p>