Doubt with use of 'pthread' in posix

0

I am using the following routine with command pthread.h library:

//
//  Declaração
//
pthread_t       threads[NUM_THREADS];

//
//  Criacao
//
for(...)
{
    pthread_create(&threads[i], NULL,   MainTH,     (void *)    &thread_args[i]);
}

//
//  execução 
//
for(...)
{
    pthread_join(threads[i], NULL);
}

That way they do not work independently, right? wait for the termination of the other Thread

I wanted to know, how do I work with them separately, independent?

    
asked by anonymous 02.08.2016 / 14:44

1 answer

0

The code seems correct to me. The pthread_create function starts execution of the non-blocking thread, that is, the thread starts executing without interrupting the mainstream. Finally, the pthread_join function waits for the completion of all threads. This blocks the main stream so that each thread is finalized one by one.

    
02.08.2016 / 15:23