Interrupting system calls in threads on Linux

I have pthread that runs in a loop, calling accept() blocking way. Is there any way to abort this call from another thread? Everything indicates sending a signal stream, but apparently you can only send a signal to a process.

I can’t just kill the stream, because then it remains open. And it is not very clean. Is there really no way to do this?

+1
source share
2 answers

You can signal a thread using pthread_kill(3) .

The pthread_kill() function sends the sig signal to a thread, another thread in the same process as the caller.

If a signal handler is installed, the handler will be called into the thread.

Note. You do not need to kill the stream ; you can send a signal that just makes accept fail with EINTR .

+3
source

Use either select() , or send the single to the process (this will be a problem if you just want to intercept one of the threads).

-1
source

Source: https://habr.com/ru/post/950132/


All Articles