TIP #335: AN API FOR DETECTING ACTIVE INTERPRETERS ==================================================== Version: $Revision: 1.8 $ Author: Joe Mistachkin State: Final Type: Project Tcl-Version: 8.6 Vote: Done Created: Monday, 13 October 2008 URL: https://tip.tcl-lang.org335.html Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP introduces the ability to quickly and safely decide whether a Tcl script is evaluating in an interpreter, allowing an external system to determine whether it is safe to delete that interpreter. RATIONALE =========== For applications written in garbage-collected languages, such as C#, it is not always desirable to rely upon the *Tcl_Preserve* / *Tcl_Release* mechanism to protect an against deletion of an interpreter while it is in use. For details of how this is used, see [] [] and Joe Mistachkin's talk at Tcl 2008. Additionally, an application may want to proactively forbid attempts to delete an interpreter while it is in use. Unfortunately, there is currently no publicly exposed method to determine if a given Tcl interpreter is in use (i.e. one or more calls to *Tcl_Eval* are active). This TIP proposes to correct that deficiency. SPECIFICATION =============== This TIP introduces a single function to Tcl's public API: int *Tcl_InterpActive*(Tcl_Interp */interp/) The *Tcl_InterpActive* function returns non-zero if the interpreter is in use, and zero if it is idle (i.e. not evaluating any script). REFERENCE IMPLEMENTATION ========================== /* *---------------------------------------------------------------------- * * Tcl_InterpActive -- * * Returns non-zero if the specified interpreter is in use. * * Results: * See above. * * Side effects: * None. * *---------------------------------------------------------------------- */ int Tcl_InterpActive(Tcl_Interp *interp) { return (((Interp *) interp)->numLevels > 0); } COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows