Is the following piece of code
if(ESRCH == pthread_kill(Thread_Id,0))
start_Thread_Again
a good way to check if my thread has accidentally exited? Can we use it similar to
wait(-1,W_NOHANG)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“Accidentally exited?” A thread does not exit accidentally, it exits because your code tells it to do so [meaning you have a bug if you didn’t want it to exit].
From the manpage for
pthread_kill: “As in kill(), if sig is zero, error checking shall be performed but no signal shall actually be sent.”Your code is wrong, it must check for equality.