other versions
- wheezy 8.4.19-5
conflicting packages
Tcl_AsyncCreate(3tcl) | Tcl Library Procedures | Tcl_AsyncCreate(3tcl) |
NAME¶
Tcl_AsyncCreate, Tcl_AsyncMark, Tcl_AsyncInvoke, Tcl_AsyncDelete, Tcl_AsyncReady - handle asynchronous eventsSYNOPSIS¶
#include <tcl.h>Tcl_AsyncHandler Tcl_AsyncCreate(proc, clientData)Tcl_AsyncMark(async)int Tcl_AsyncInvoke(interp, code)Tcl_AsyncDelete(async)int Tcl_AsyncReady()
ARGUMENTS¶
- Tcl_AsyncProc *proc (in)
- Procedure to invoke to handle an asynchronous event.
- ClientData clientData (in)
- One-word value to pass to proc.
- Tcl_AsyncHandler async (in)
- Token for asynchronous event handler.
- Tcl_Interp *interp (in)
- Tcl interpreter in which command was being evaluated when handler was invoked, or NULL if handler was invoked when there was no interpreter active.
- int code (in)
- Completion code from command that just completed in
interp, or 0 if interp is NULL.
DESCRIPTION¶
These procedures provide a safe mechanism for dealing with asynchronous events such as signals. If an event such as a signal occurs while a Tcl script is being evaluated then it isn't safe to take any substantive action to process the event. For example, it isn't safe to evaluate a Tcl script since the interpreter may already be in the middle of evaluating a script; it may not even be safe to allocate memory, since a memory allocation could have been in progress when the event occurred. The only safe approach is to set a flag indicating that the event occurred, then handle the event later when the world has returned to a clean state, such as after the current Tcl command completes. Tcl_AsyncCreate, Tcl_AsyncDelete, and Tcl_AsyncReady are thread sensitive. They access and/or set a thread-specific data structure in the event of a core built with --enable-threads. The token created by Tcl_AsyncCreate contains the needed thread information it was called from so that calling Tcl_AsyncMark(token) will only yield the origin thread into the asynchronous handler. Tcl_AsyncCreate creates an asynchronous handler and returns a token for it. The asynchronous handler must be created before any occurrences of the asynchronous event that it is intended to handle (it is not safe to create a handler at the time of an event). When an asynchronous event occurs the code that detects the event (such as a signal handler) should call Tcl_AsyncMark with the token for the handler. Tcl_AsyncMark will mark the handler as ready to execute, but it will not invoke the handler immediately. Tcl will call the proc associated with the handler later, when the world is in a safe state, and proc can then carry out the actions associated with the asynchronous event. Proc should have arguments and result that match the type Tcl_AsyncProc:typedef int Tcl_AsyncProc( ClientData clientData, Tcl_Interp * interp, int code);
WARNING¶
It is almost always a bad idea for an asynchronous event handler to modify the interpreter's result or return a code different from its code argument. This sort of behavior can disrupt the execution of scripts in subtle ways and result in bugs that are extremely difficult to track down. If an asynchronous event handler needs to evaluate Tcl scripts then it should first save the interpreter's result plus the values of the variables errorInfo and errorCode (this can be done, for example, by storing them in dynamic strings). When the asynchronous handler is finished it should restore the interpreter's result, errorInfo, and errorCode, and return the code argument.KEYWORDS¶
asynchronous event, handler, signal7.0 | Tcl |