Pthread in linux C

Hi,
I have two doubts in thread programming in linux.
1. I declare thread as detached thread in linux c program. How can i know ,when thread is exited or not. i tried pthread_join, but it is not giving correct value.

2. Is there any way to again restart the thread after its exist? whether that is detached or join thread.
1. threads aren't declared, they are created and manipulated. If you created a detached thread using pthread_attr_setdetachstate() or converted a joinable thread into a detached thread by calling pthread_detach(), then this thread cannot be joined or made joinable again, ever.

If some other thread needs to know if your detached thread is still running, write code that modifies some variable or sends a message on thread exit, e.g. with pthread_cleanup_push()

Note that if you google your question, you may see the hack "pthread_kill(tid, 0)!=ESRCH", it's not guaranteed to work for detached threads.

2. You can create a new thread with the same thread function, data, and attributes.
if we can create a new thread with the same thread function, data, and attributes, then why pthread_once is there. I am confused here. Can you clear it?
pthread_once is not related to launching/exiting threads. It's a form of synchronization between threads that are already running.
Topic archived. No new replies allowed.