title: Using parameters with threads
body: <p>I'm using the linux pthreads library to try the threads features, the code below prints 5 messages on the screen for each thread, each thread waits its turn to display the message controlled using the semaphores, in Windows it works perfectly, but in linux the threads do not wait their turn, I already researched everything that is singing and I could not reach a solution to this problem. My deduction is that I'm doing something wrong with the parameter struct</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;semaphore.h&gt;
  #include &lt;stdio.h&gt;
  
  typedef struct param{
    int id;
    pthread_mutex_t lock;
    sem_t semaforo;
  }valores_t;
  
  void * olamundo(void* args){
    valores_t* p = args;
    sem_wait(&amp;p-&gt;semaforo);
    for (size_t i = 0; i &lt; 5; i++) {
      printf("Hello from thread %d\n", p-&gt;id);
    }
    sem_post(&amp;p-&gt;semaforo);
  }
  
  sem_t semaforo;
  
  int main(int argc, char const *argv[]) {
    /* code */
  
    if(sem_init(&amp;semaforo,0,1)){//valor inicial do semaforo começa por 1
      printf("Error\n");
    }
  
    valores_t p[2];
    pthread_t threads[2];
  
      p[0].id = 1;
      p[0].semaforo = semaforo;
  
      p[1].id = 2;
      p[1].semaforo = semaforo;
  
    for(int i = 0; i &lt; 2; i++){
      if(pthread_create(&amp;(threads[i]), NULL, &amp;olamundo, &amp;p[i]) == -1){
        printf("Error\n");
      }
    }
  
    for(int i = 0; i &lt; 2; i++){
          if(pthread_join(threads[i], NULL)){
        printf("Error\n");
      }
      }
      sem_destroy (&amp;semaforo);
    return 0;
  }
  </code></pre>