News for hackers. Stuff that matters.
Re:How to stop Linux threads cleanly by cyberax on Monday October 20, 2025 @03:09PM (#45647883)
I had this problem, and I solved it by farming the known-blocking syscalls to a separate thread pool. Then the calling thread can just abandon the wait. To make it a bit better, you can also use bounded timeouts (~1-2 seconds) with retries for some calls like recvfrom() via SO_TIMEOUT so that the termination time becomes bounded.

This is probably the cleanest solution that is portable.

Re:How to stop Linux threads cleanly by naasking on Tuesday October 21, 2025 @12:45PM (#45657988)
Then those thread pool threads have to be careful not to take locks and other scarce resources that aren't cleaned up then, no?
Re:How to stop Linux threads cleanly by cyberax on Tuesday October 21, 2025 @04:07PM (#45661006)
Sure. But if you only use it to run blocking requests, it's probably going to be pretty trivial. It won't be super-high performance because of all the cache bounces, but if you're not using something like epoll, then you probably are not really focused on performance anyway.