TIP #335: An API for Detecting Active Interpreters


TIP:335
Title:An API for Detecting Active Interpreters
Version:$Revision: 1.8 $
Author:Joe Mistachkin <joe at mistachkin dot com>
State:Final
Type:Project
Tcl-Version:8.6
Vote:Done
Created:Monday, 13 October 2008
Keywords:numLevels, embedding, terminate, async, thread, safe, gc

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 [1] [2] 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.


Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows