ashfaq ashfaq - 3 months ago 22
C Question

Pthreads - Can I detach from a thread and then join in main?

What I want to do is something on lines of...

pthread_create(&producer_thread, &to_join, producer_routine, &queue);
pthread_detach(producer_thread);
...
...
pthread_join(producer_thread, NULL);


Is this possible in some way, on running the above code, it is unable to join the thread.

Answer

Once detached, it's not possible to join anymore.

From pthread_join(3) man page:

Once a thread has been detached, it can't be joined with pthread_join(3) or be made joinable again.

Comments