[Tickets] [Orxonox] #335: Terminate Tcl threads

Orxonox trac at orxonox.net
Sun Jul 19 03:08:06 CEST 2009


#335: Terminate Tcl threads
--------------------------+-------------------------------------------------
 Reporter:  landauf       |       Owner:  landauf                        
     Type:  defect        |      Status:  new                            
 Priority:  normal        |   Milestone:  Version 0.2 Codename: Bellatrix
Component:  ScriptEngine  |     Version:  0.2.0                          
 Severity:  normal        |    Keywords:  tcl                            
--------------------------+-------------------------------------------------
 Right now Tcl threads (see [wiki:TclThreadManager]) can't be terminated if
 the corresponding Tcl interpreter is executing an endless
 ([http://www.tcl.tk/man/tcl8.4/TclCmd/while.htm while]) or long
 ([http://www.tcl.tk/man/tcl8.4/TclCmd/for.htm for]) loop or waiting for a
 condition ([http://www.tcl.tk/man/tcl8.4/TclCmd/vwait.htm vwait]) or
 simply sleeping ([http://www.tcl.tk/man/tcl8.4/TclCmd/after.htm after])
 and maybe it's even possible to hang on an open stream
 ([http://www.tcl.tk/man/tcl8.4/TclCmd/exec.htm exec] and
 [http://www.tcl.tk/man/tcl8.4/TclCmd/open.htm#M20 open with a pipe]).

 Since Tcl doesn't know keywords, all those language features are functions
 which can be overwritten with
 [http://www.tcl.tk/man/tcl8.4/TclCmd/proc.htm 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 [http://www.tcl.tk/man/tcl8.4/TclLib/contents.htm 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.

-- 
Ticket URL: <http://www.orxonox.net/ticket/335>
Orxonox <http://www.orxonox.net>
Orxonox Open Source game


More information about the Tickets mailing list