Doubt with use of`pthread` in Posix

Asked

Viewed 119 times

0

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

//
//  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 don’t work independently, right? await the termination of the other Thread

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

1 answer

0

The code seems correct. The pthread_create function starts the thread execution without locking, that is, the thread runs without interrupting the main stream. Finally, the pthread_join function awaits completion of all threads. This blocks the main flow so that each thread is finished one by one.

  • yes, but only removing this function will make them work independently, it will not occur of the program to close since the main will not wait for threads and enter reach the end?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.