What is a cancellation point?

I am trying to understand what exactly is the undo point in C ++. I read:

man page and What are pthread revocation points for

But I'm still a little confused at certain points. For example, I use the write () function of a file. Apparently, this is the cancellation point. Therefore, when I call write (), I see that another thread can start processing (therefore, my code switches from the write stream to another stream), this usually happens when the write buffer is full and needs to be cleared before writing () succeeds / to complete.

But, in my opinion, this is not a cancellation of the thread, but just a temporary block / pause, and there is no "cleanup" thread to execute ...

So my question is, do undo points relate to “lock points”? “Are they really the same, or is there any difference?” Any clear “top” description of what the cancel point will be really helpful.

+7
c ++ cancellation
source share
2 answers

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

+8
source share

If you want to terminate or cancel a thread from another thread (for example, the main thread) using pthread_cancel() , the following will happen ( cf ):

The pthread_cancel() function sends a cancel request to the thread stream.

The target thread will not complete immediately, but when it reaches the cancel point ( cf ):

POSIX.1 indicates that certain functions should and some other functions may be undo points. If a thread is canceled, its cancellation type is canceled, and the cancellation request is pending for the thread, then the thread is canceled when it calls a function that is the cancel point.

Regardless of whether these functions, which are a cancellation point, can also block the execution of a thread, they are currently not relevant. The documentation has a list of these functions:

Please note that there are settings that can affect the behavior and “cancel” the stream, which I left here for simplicity. For further reading:

+5
source share

All Articles