<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu May 17 04:23:18 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='335'>
<header><title>An API for Detecting Active Interpreters</title><author address="mailto:joe@mistachkin.com">Joe Mistachkin</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.8 $</status><history></history><created day='13' month='oct' year='2008' /><keyword>numLevels embedding terminate async thread safe gc</keyword></header>
<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.</abstract>
<body><section title="Rationale">
<para>For applications written in garbage-collected languages, such as C#, it is not always desirable to rely upon the <emph style="bold">Tcl_Preserve</emph> / <emph style="bold">Tcl_Release</emph> mechanism to protect an against deletion of an interpreter while it is in use. For details of how this is used, see [<url ref="http://wiki.tcl.tk/6580"/>] [<url ref="http://eagle.to/"/>] and Joe Mistachkin&apos;s talk at Tcl 2008.</para>
<para>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 <emph style="bold">Tcl_Eval</emph> are active). This TIP proposes to correct that deficiency.</para>
</section>
<section title="Specification">
<para>This TIP introduces a single function to Tcl&apos;s public API:</para>
<quote>int <emph style="bold">Tcl_InterpActive</emph>(Tcl_Interp *<emph style="italic">interp</emph>)</quote>
<para>The <emph style="bold">Tcl_InterpActive</emph> function returns non-zero if the interpreter is in use, and zero if it is idle (i.e. not evaluating any script).</para>
</section>
<section title="Reference Implementation">
<verbatim><vline encoding='base64'>Lyo=</vline><vline encoding='base64'>ICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICogVGNsX0ludGVycEFjdGl2ZSAtLQ==</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICoJUmV0dXJucyBub24temVybyBpZiB0aGUgc3BlY2lmaWVkIGludGVycHJldGVyIGlzIGluIHVzZS4=</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICogUmVzdWx0czo=</vline><vline encoding='base64'>ICoJU2VlIGFib3ZlLg==</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICogU2lkZSBlZmZlY3RzOg==</vline><vline encoding='base64'>ICoJTm9uZS4=</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t</vline><vline encoding='base64'>ICov</vline><vline encoding='base64'></vline><vline encoding='base64'>aW50</vline><vline encoding='base64'>VGNsX0ludGVycEFjdGl2ZShUY2xfSW50ZXJwICppbnRlcnAp</vline><vline encoding='base64'>ew==</vline><vline encoding='base64'>ICAgIHJldHVybiAoKChJbnRlcnAgKikgaW50ZXJwKS0+bnVtTGV2ZWxzID4gMCk7</vline><vline encoding='base64'>fQ==</vline></verbatim>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

