Interrupting syscalls in threads on linux
I have a pthread that runs in a loop, calling accept()
in a blocking manner. Is there any way to interrupt that call from another thread? Everything points to sending the thread a signal, but apparently you can only send a process a signal.
I can't j开发者_Go百科ust kill the thread because then it leaves the socket open. And that's not very clean anyway. Is there really no way to do this?
You can signal a thread using pthread_kill(3)
.
The
pthread_kill()
function sends the signal sig to thread, another thread in the same process as the caller.If a signal handler is installed, the handler will be invoked in the thread thread.
Note, you don't have to kill the thread; you can send a signal that simply makes accept
fail with EINTR
.
Either use select()
, or send the singal to the process (this will be a problem if you just want to interupt one of the threads).
精彩评论