title: Trying to understand C code(semaphores & syncing them)
body: <p>I'm trying to understand some C code regarding operating system /Creating threads syncing </p>
  
  <pre><code>line 1: targs[0]-&gt;id=1; /* thread number 1 */
  line 2: targs[0]-&gt;sec=1; /* how long to sleep */
  line 3: targs[0]-&gt;signal[1]=1; /* which threads to wake up when done */
  line 4: targs[0]-&gt;signal[4]=1;
  line 5: sem_init(&amp;sem[targs[0]-&gt;id-1],SHARED,1); /* start waiting or running? */
  line 6: pthread_create(&amp;tid[0], NULL, tfunc, (void *) targs[0]);
  </code></pre>
  
  <p>My question is. What does "sem_init()" do?, on line 5: by the ((&amp;sem[targs[0]->id-1],SHARED,1);), "&amp;sem" referrs to the array i made which is not here, the targs[0] gets an Id minus 1? is this correct?</p>
  
  <p>pthread_create= creates a thread, which has to be zero for it to run? </p>