On 25.12.2006, at 11:22, Zoran Vasiljevic wrote:

It seems that
stdin/stdout/stderr channels are not properly handled
on thread exit (not detached from the interp).

Well, this is going to be tough...

The scenario is simple: Tcl has channel wrappers for stdin,
stdout and stderr channels. On a virgin interp and new
thread the first call to some channel handling command will
try to initialize per-interp channel table.  This in turn
will try to get all those three std channels  initialized.

On interp teardown, those channels are not removed (Tcl_Close'd)
as this may result in closing of the underlying descriptor for
the whole process! Hence those three chans are never closed!

Therefore, you leak 3 channels every time you exit a thread
that uses Tcl and some of the channel commands.
In our case, we ALWAYS leak 3 channels. As the part of the interp
deallocation, we always try to close non-stderr channels and thus
invoke [file channels] that in turn lazy-initialize std channels.

Shortly: Tcl always creates 3 channels arround stdin/stderr/stdout
descriptors for a new thread/interp.  Tcl never closes those channels
on thread exit, as this will close the underlying descriptor and have
large side-effect on whole process.
The only chance is to artificially plumb the channel structure and
remove (or redefine) closeproc elements for std channels.
This is a GREAT mess and I will have to wait for Andreas (Kupries)
to come back from vacation so we can jointly attack that stupid bug.




Reply via email to