When your thread is pulled from execution, its state is saved by the OS and is not a thread cancellation. Cancellation means the completion of the flow upon request with the special intention of allowing everything in the final state at the end (otherwise, all resources will be released, all handlers will be updated, etc.).
What you call a lock can happen to a thread when it is canceled in the middle.
Example: a thread receives a cancel request. The operating system queues it until the thread is canceled. When a thread becomes canceled and the thread executes a cancel point, the thread can be cleared and undone. The write function is a cancellation point, which means that from the OS point of view, it is safe to cancel a thread during the execution of this function (the state of all related resources will be consistent).
While the cancel procedure is in progress, the thread can be blocked as many times as it is suitable for the OS.
As an additional note, if you look at the POSIX requirement for undo points, almost all blocking interfaces should be undo. Otherwise, on any completely blocked thread (in such a call) there would be no safe way to terminate this thread.
http://man7.org/linux/man-pages/man7/pthreads.7.html
Bogdan V.
source share