Description Methods and Functions Hierarchy Detailed Description Structures Convenient Construction Signals Author(s) References
Thread-safe Operation Cancellation Stack
gCancellableNew()
gCancellableIsCancelled(object)
gCancellableSetErrorIfCancelled(object, .errwarn = TRUE)
gCancellableGetFd(object)
gCancellableReleaseFd(object)
gCancellableGetCurrent()
gCancellablePopCurrent(object)
gCancellablePushCurrent(object)
gCancellableReset(object)
gCancellableDisconnect(object, handler.id)
gCancellableCancel(object)
gCancellable()
1 2 | GObject
+----GCancellable
|
GCancellable is a thread-safe operation cancellation stack used throughout GIO to allow for cancellation of synchronous and asynchronous operations.
GCancellable
Allows actions to be cancelled.
gCancellable
is the equivalent of gCancellableNew
.
cancelled(cancellable, user.data)
Emitted when the operation has been cancelled.
Can be used by implementations of cancellable operations. If the operation is cancelled from another thread, the signal will be emitted in the thread that cancelled the operation, not the thread that is running the operation.
Note that disconnecting from this signal (or any signal) in a
multi-threaded program is prone to race conditions. For instance
it is possible that a signal handler may be invoked even
after a call to
gSignalHandlerDisconnect
for that handler has already
returned.
There is also a problem when cancellation happen right before connecting to the signal. If this happens the signal will unexpectedly not be emitted, and checking before connecting to the signal leaves a race condition where this is still happening.
In order to make it safe and easy to connect handlers there
are two helper functions: gCancellableConnect()
and
gCancellableDisconnect
which protect against problems
like this.
An example of how to us this:
## Make sure we don't do any unnecessary work if already cancelled if (cancellable$setErrorIfCancelled()) return() ## Set up all the data needed to be able to ## handle cancellation of the operation my_data <- myData(...) id <- 0 if (!is.null(cancellable)) id <- cancellable$connect(cancelled_handler, data, NULL) ## cancellable operation here... cancellable$disconnect(id)
Note that the cancelled signal is emitted in the thread that the user cancelled from, which may be the main thread. So, the cancellable signal should not do something that can block.
cancellable
a GCancellable
.
user.data
user data set when the signal handler was connected.
Derived by RGtkGen from GTK+ documentation
https://developer.gnome.org/gio/stable/GCancellable.html
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.