Pthread_killGrammar
tidsig);
sigtidret;ret = Pthread_kill ( tid sig );
pthread_kill()Sends the signal SIG to the thread specified by the tid . The thread specified by the tid must be in the same process as the calling thread. The sig parameter must come from the list provided by signal (5).
sends a SIG signal to a thread of the specified ID if the thread code does not handle it, the entire process is affected by the default behavior of the signal, that is, if you send a sigquit to a thread, but the thread does not implement the signal handler, the entire process exits.
Pthread_kill (ThreadID, SIGKILL), too, kills the whole process.
If you want to get the right behavior, you need to implement signal (Sigkill,sig_handler) within the thread.
So, if the int sig parameter is not 0, it must be clear exactly what to do, and must implement the signal processing function of the thread, otherwise, it will affect the entire process.
OK, if the int sig is 0, this is a reserved signal and a function is used to determine if the thread is still alive (the error check is performed, but the signal is not actually sent.) This error check can be used to check the validity of the tid . )。
Pthread_killreturn value
pthread_kill()Returns zero after a successful completion. Any other return value indicates an error occurred. If any of the following conditions occur, the pthread_kill() corresponding value will fail and be returned.
EINVAL
Describe:
sigis a semaphore that is not valid.
Esrch
Describe:
Cannot be found in the current process tid .
Sending a signal to a thread in Pthread