Create threads without pthread_join in C
<p>In this segment of code, how can I create those threads without the use of the function <code>pthread_join()</code>? Using <code>pthread_exit()</code> didn't work.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;pthread.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/stat.h&gt;
typedef struct{
    char name[100];
    char search[100];
    pthread_t tid;
} mystruct;
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
void* sfun(void *arg){
    mystruct *sfile= (mystruct *) arg;
    int fd=open(sfile-&gt;name,O_RDONLY);
    if(fd&lt;0){
        printf("Error%s\n", sfile-&gt;name);
        pthread_exit(NULL);
    }
    int n=1;
    pthread_mutex_lock(&amp;mutex);
    while(n!=0){
        n=match_line(fd,sfile-&gt;search);
        printf("%s:\t%d\n",sfile-&gt;name,n);
    }
    pthread_mutex_unlock(&amp;mutex);
    close(fd);
    return NULL;
}

int main(int argc, char *argv[]){
    if(argc&lt; 3){
        printf("Error\n");
        exit(1);
    }
    mystruct file[10];//max 10 threads
    int c;
    for(c=0;c&lt;argc-2;c++){
    strcpy(file[c].search,argv[1]);
    strcpy(file[c].name,argv[c+2]);
    pthread_create(&amp;file[c].tid,NULL,sfun,&amp;file[c]);
    }
    for(c=0;c&lt;argc-2;c++)
        pthread_join(file[c].tid,NULL);
    return 0;

}
</code></pre>

<p>Compiled with <code>pthread_join()</code>:  </p>

<pre><code>./ppc "Sherlock" testfile1 testfile2 testfile12

testfile1:  5
testfile1:  762
testfile1:  960
testfile1:  977
testfile1:  1025
testfile1:  1034
testfile1:  1049
testfile1:  1068
testfile1:  1080
testfile1:  1123
testfile1:  0
testfile2:  3
testfile2:  90
testfile2:  170
testfile2:  179
testfile2:  473
testfile2:  643
testfile2:  760
testfile2:  811
testfile2:  836
testfile2:  978
testfile2:  0
testfile12: 5
testfile12: 762
testfile12: 960
testfile12: 977
testfile12: 1025
testfile12: 1034
testfile12: 1049
testfile12: 1068
testfile12: 1080
testfile12: 1123
testfile12: 1129
testfile12: 1216
testfile12: 1296
testfile12: 1305
testfile12: 1599
testfile12: 1769
testfile12: 1886
testfile12: 1937
testfile12: 1962
testfile12: 2104
testfile12: 0
</code></pre>

<p>with no <code>pthread_join()</code> it won't print anything!</p>