title: sem_wait not working in basic code
body: <p>Compiled with gcc.  I ran this to see why the semaphores I was using in my other programs were not working correctly.  Am I just using these them incorrectly or what? The string is outputted every time even though the semaphore should halt execution and cause a deadlock, right?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;semaphore.h&gt;
  #include &lt;stdlib.h&gt;
  #define NUM_THREADS 5
  void printHello();
  int main(){
      int i;
      pthread_t threads[NUM_THREADS];
      sem_t sem1;
      sem_init(&amp;sem1, 0, 0);
      sem_wait(&amp;sem1);
  
      for(i = 0; i &lt; NUM_THREADS; i++){
          pthread_create(&amp;threads[i], NULL, &amp;printHello, NULL);
      }
  
      sem_destroy(&amp;sem1);
      pthread_exit(NULL); 
  
          return 0;
  }
  
  void printHello(){
      printf("sem_wait failed\n");
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated as I am trying to grasp the whole multithreading concept.</p>
  
  <p>Thanks!</p>