Comment

Comment by the_duke

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.

parent the_duke 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton