r/programming • u/ketralnis • Oct 20 '25
How to stop Linux threads cleanly
https://mazzo.li/posts/stopping-linux-threads.html6
u/Yesterday622 Oct 21 '25
Reboot?
1
u/NuncioBitis Oct 21 '25
That's an old term. It's now "perform rebootification"
Like we now have "configurationer"
2
u/NuncioBitis Oct 21 '25
The picture provided is misleading...
This mage lost his cat to a parallel dimension.
He's sending it a ball of string to keep it occupied.
1
u/Geertiebear Oct 21 '25
Hello! Not sure if OP is the author of the article, but the following isn't technically correct.
By default the signal sent by thread cancellation is only received at “cancellation points”, which to a first approximation are the syscalls that might block – see pthreads(7).
This actually depends on the type of cancellation enabled, it can be asynchronous or deferred. On asynchronous cancellation the thread will be cancelled using a signal. But on deferred cancellation the system exhibits the behaviour described above, only it doesn't usually work through a signal, but rather with an atomically set flag.
1
0
u/Middlewarian Oct 21 '25
Io-uring is often able to help minimize the number of threads needed. I'm taking a single-threaded approach with my code generator and hope to scale with multiple processes.
-1
78
7
u/SeniorScienceOfficer Oct 21 '25
kill -9 $PID
11
u/FlyingRhenquest Oct 21 '25
If you do that in a thread group that you're in you'll end up killing yourself in the process. It's really the messiest way to do it.
14
15
u/knome Oct 21 '25
how to stop linux threads /in C or C++/. a different language could be compiled so that the stackunwinding in the targeted thread doesn't have the same resource releasing issues. that is, it could do what C++ does, but without noexcept blocks causing instant failures.
that aside, damned good technical article.