Cancel, interrupt and thread.stop() are three less-quizzed topics that show up occasionally in java/c++ interviews. They are fundamental features of the concurrency API. You can consider this knowledge as zbs.
As described in ##thread cancellation techniques: java #pthread,c#, thread cancellation is supported in c# and pthreads, whereas java indirectly supports it.
— cancel and java thread.stop() are semantically identical but java thread.stop() is forbidden and unsafe.
PTHREAD_CANCEL_ASYNCHRONOUS is usable in very restricted contexts. I think this is similar to thread.stop().
— cancel and interrupt both define stop points. In both cases, the target thread choose to ignore the cancellation/interrupt request, or check them at the stop points.
Main difference between cancel and interrupt ? Perhaps just the wording. In pthreads there’s only cancel, no interrupt, but in java there’s no cancel.
Note interrupted java thread probably can’t resume.
Nos sure if Unix signal handler also supports stop points.
Java GC on-request is also cooperative. You can’t force the GC to start right away.
Across the board, the only immediate (non-cooperative) mechanism is power loss. Even a keyboard “kill” is subject to software programmed behavior, typically the OS scheduler.