Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For interrupting long-running syscalls there is another solution:

Install an empty SIGINT signal handler (without SA_RESTART), then run the loop.

When the thread should stop:

* Set stop flag

* Send a SIGINT to the thread, using pthread_kill or tgkill

* Syscalls will fail with EINTR

* check for EINTR & stop flag , then we know we have to clean up and stop

Of course a lot of code will just retry on EINTR, so that requires having control over all the code that does syscalls, which isn't really feasible when using any libraries.

EDIT: The post describes exactly this method, and what the problem with it is, I just missed it.



This option is described in detail in the blog posts, with its associated problems, see this section: https://mazzo.li/posts/stopping-linux-threads.html#homegrown... .


Ah, fair, I missed it when reading the post because the approach seemed more complicated.


I mean that's the reason EINTR exists at all.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: