News for hackers. Stuff that matters.
Re:How to stop Linux threads cleanly by quotemstr on Monday October 20, 2025 @01:42PM (#45646785)
pthread cancelation ends up not being the greatest, but it's important to represent it accurately. It has two modes: asynchronous and deferred. In asynchronous mode, a thread can be canceled any time, even in the middle of a critical section with a lock held. However, in deferred mode, a thread's cancelation can be delayed to the next cancelation point (a subset of POSIX function calls basically) and so it's possible to make that do-stuff-under-lock flow safe with cancelation after all.

That's not to say people do or that it's a good idea to try.

Re:How to stop Linux threads cleanly by rostayob on Monday October 20, 2025 @01:50PM (#45646891)
Cancellation points and cancellability state are discussed in the post. In a C codebase that you fully control pthread cancellation _can_ be made to work, but if you control the whole codebase I'd argue you're better off just structuring your program so that you yield cooperatively frequently enough to ensure prompt termination.
Re:How to stop Linux threads cleanly by quotemstr on Monday October 20, 2025 @02:25PM (#45647323)
Not arguing there. I'm just pointing out that the post's claim that " Thread cancellation is incompatible with modern C++" needs more nuance.