I am in the same situation as this guy, but I don't quite understand the answer.
The problem:
- Thread 1 calls
accept
on a socket, which is blocking. - Thread 2 calls
close
on this socket. - Thread 1 continues blocking. I want it to return from accept.
The solution:
what you should do is send a signal to the thread which is blocked in accept. This will give it EINTR and it can cleanly disengage - and then close the socket. Don't close it from a thread other than the one using it.
I don't get what to do here -- when the signal is received in Thread 1, accept
is already blocking, and will continue to block after the signal handler has finished.
- What does the answer really mean I should do?
- If the Thread 1 signal handler can do something which will cause
accept
to return immediately, why can't Thread 2 do the same without signals? - Is there another way to do this without signals? I don't want to increase the caveats on the library.