Threading using pthread
<p>Let say I have an array of  5 threads :</p>

<pre><code>//main thread
pthread_t t[5];
pthread_mutex_t mutex[5];
queue&lt;int&gt; q[5];

for(int i = 0; i &lt; 5; i++){
pthread_create(&amp;pthread_t[i], NULL, worker, NULL);
}

for(int i = 0; i &lt; 5; i++){
   pthread_mutex_lock(&amp;mutex[i]);
      queue[i].push_back(i);
   pthread_mutex_unlock(&amp;mutex[i]);
}

void* worker(void* arg){

    pthread_mutex_lock(&amp;mutex[?]);      

}
</code></pre>

<p>I am confused with the mutex_lock here. My question is:</p>

<ol>
<li>How could I let the worker know which mutex to lock?</li>
<li>When I access the mutex through mutex[i], do I need another lock since the child thread might be accessing the mutex array as well?</li>
</ol>

<p>Thanks.</p>
