Reputation: 96556
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 just 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?
Upvotes: 3
Views: 3746
Reputation: 36433
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).
Upvotes: -1
Reputation: 182619
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
.
Upvotes: 7