News for hackers. Stuff that matters.
Re:How to stop Linux threads cleanly by the_duke on Monday October 20, 2025 @01:08PM (#45646339)
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.

Re:How to stop Linux threads cleanly by rostayob on Monday October 20, 2025 @01:43PM (#45646809)
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... .
Re:How to stop Linux threads cleanly by the_duke on Monday October 20, 2025 @01:56PM (#45646975)
Ah, fair, I missed it when reading the post because the approach seemed more complicated.
Re:How to stop Linux threads cleanly by 1718627440 on Tuesday October 21, 2025 @08:10AM (#45654847)
I mean that's the reason EINTR exists at all.