title: C thread-mutex codes errors?
body: <p>Here is the code:</p>
  
  <pre><code>....
  typedef struct {
    int buf[10];
    long head, tail;
    int full, empty;
    pthread_mutex_t *mut;
    pthread_cond_t *notFull, *notEmpty;
  } queue;
  
  int main(){
    queue *que;
    pthread_t sup, cut;
    que = queueInit();
    if(que == NULL){
      fprintf(stderr, "Queue Init failed");
      exit(1);
    }
    pthread_create(&amp;sup, NULL, insertQueue, (void*) que);
    pthread_create(&amp;cut, NULL, insertQueue, (void*) que);
    pthread_join(sup,NULL);
    pthread_join(cut,NULL);
    queueDelete(que);
    return 0;
  }
  
  void *insertQueue(void *q)
  {
    queue *que;
    int i;
    que = (queue *)q;
    for(i=0; i&lt;20;i++){
      // Get mutex lock on the queue
      pthread_mutex_lock(&amp;mut); // Question (i) I guess this line is wrong
      while(que&gt;full){
        printf("Its full");
        // pthread wait condition for queue not full
        pthread_cond_wait(&amp;notFull, &amp;mut); // Question (ii)
      }
      queueAdd(que,i);
      // Unlock the queue
      pthread_mutex_unlock(&amp;mut); // Question (iii)
      // Send signal saying there is data to be read
      pthread_cond_signal(&amp;notEmpty); // Question (iv)
      usleeep(100000);)
      return(NULL);
    }
  }
  
  queue *queueInit(void){
    queue *q;
    q = (queue *)malloc(sizeof(queue));
    if(q==NULL) return (NULL);
    q-&gt;empty = 1;
    q-&gt;full = 0;
    q-&gt;head = 0;
    q-&gt;tail = 0;
    q-&gt;mut=(pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
    // Set default condition
    pthread_mutex_init(&amp;mut,NULL); // Question v
    // Condition for not null
    pthread_mutex_init(&amp;notNull,NULL); // Question vi
    // Condition for not empty
    pthread_mutex_init(&amp;notEmpty,NULL); // Question vi
    return (q);
  }
  ....
  </code></pre>
  
  <p>I have put my question in the code, i.e question i - vi</p>
  
  <p>My feeling telling me, my arguments are wrong, for example the question vi:</p>
  
  <pre><code>pthread_cond_init(notEmpty,NULL);
  </code></pre>
  
  <p>it should be something else, not "(&amp;notEmpty,Null)". </p>
  
  <p>Please help.</p>