|
|
|
|
|
by rdtsc
4328 days ago
|
|
Have you tried: * closing the socket (it would be from another, monitoring thread in this case) * setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO) * Would that be different than blocking on select with a an infinite timeout. How do you cancel that? Or are you relying on other sockets getting constant stream of data to wake you up? * do something with an ALARM signal |
|
A timeout will work fine, but now you're polling, meaning you have an unpleasant tradeoff between efficiency and how long it takes for your thread to notice that it's dead.
Canceling select or any other multi-fd call is really easy. Create a pipe and add it to your fd set. Any time you want the thread to wake up (e.g. because you need to tell it that you're canceling something) you just write to the pipe.
Signals have a similar race condition as closing the socket. If the signal is delivered after you check for cancellation but before you enter the system call, you'll hang.