Threads exiting before joining
<p>Forgive me I'm just beginning the concept of multi-threading, I was just wondering why my threads might be exiting before they're joined. Essentially, I am maintaining a global list of process id's, I create them iteratively by calling   </p>

<pre><code>   if(pthread_create(&amp;thread_id[i], NULL, function_to_execute, NULL)) {
        fprintf(stderr, "error thread not created\n"); 
    }
</code></pre>

<p>Now the problem is, all my threads are exiting before they get to my pthread join </p>

<pre><code>pthread_join(thread_id[i], NULL);
</code></pre>

<p>which is deeply nested in a function call, which is called directly after the threads are created. I'm not sure if I'm suppose to do some locking or something, or add an additional command to make sure the threads wait until the join statement before exiting. </p>