If you have a worker thread that has a hot loop that checks a pthread structure as its limit. You can then send a virtual interrupt to it, or preempt it from running further by setting the loop to its limit.
You can see my C, Java and Rust code of this in this repository: https://github.com/samsquire/preemptible-thread
It can be used to create extremely responsive software without slowing down the system with cancellation checks.
https://github.com/samsquire/ideas4#120-cancellation-trees https://github.com/samsquire/ideas4#99-register-loop