Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Opened 15 years ago

#335 new defect

Terminate Tcl threads

Reported by: landauf Owned by: landauf
Priority: minor Milestone: Version 0.2 Codename: Bellatrix
Component: ScriptEngine Version: 0.2.0
Keywords: tcl Cc:
Referenced By: References:

Description

Right now Tcl threads (see TclThreadManager?) can't be terminated if the corresponding Tcl interpreter is executing an endless (while) or long (for) loop or waiting for a condition (vwait) or simply sleeping (after) and maybe it's even possible to hang on an open stream (exec and open with a pipe).

Since Tcl doesn't know keywords, all those language features are functions which can be overwritten with proc. For example you could redefine while and for with an additional condition which becomes false as soon as you want to terminate the interpreter. Unfortunately this isn't as easy as expected, because you need some deep knowledge of Tcl including it's scoping policy and how to circumvent it.

But maybe there's another way to safely terminate an interpreter. Tcl offers many functions and one of them might be the right one. But remember, you can't just crash the thread, it will crash everything. Except maybe with an ugly hack using a signal handler, but that won't be platform independent.

A third option might be to simply interrupt the thread without even trying to stop the interpreter. That won't give us our memory back, but it surely will free the CPU which might be good enough if everything else fails.

Fourth an last option that comes to my mind: As far as I know, Tcl uses some sort of events. Maybe it's possible to set up an event handler in Tcl and later inject the event through the Tcl C API to call the event handler which terminates the interpreter. Maybe not.

Change History (0)

Note: See TracTickets for help on using tickets.