From: Alexandre Ferrieux on
On Oct 7, 6:59 am, Jens Benner <jens.ben...(a)gmx.net> wrote:
> Christian Nassau schrieb:
>
>
>
> > Jens Benner wrote:
> >> In every thread id do the following things:
>
> >> // On thread Startup
> >> TclInterp = Tcl_CreateInterp();
> >> Tcl_FindExecutable(NULL);
> >> Tcl_CreateCommand(TclInterp, "myCallback", TclCallbackCmd,
> >> (ClientData)this, (Tcl_CmdDeleteProc*) NULL);
> >> Tcl_EvalFile(TclInterp, "MySript.tcl");
> >> ...
>
> > The purpose of "Tcl_FindExecutable(NULL);" is to initialize all of the
> > subsystems that the other Tcl calls rely on. You should therefore call
> > it *only once* when your application starts, and *before* any worker
> > thread is spawned.
>
> > Apart from that your setup looks fine to me.
>
> > HTH,
>
> Hello Christian,
>
> the application loads a lot of modules (dlls) via dynamically via
> loadlibrary(). In one of these modules I integrated the Tcl interpreter.
> So only this module is linked against tcl84t.lib/tcl84t.dll. The Module
> is unloaded after work and loaded again if there is work to do.
> So do I have to call Tcl_FindExecutable(NULL) every time the module is
> loaded? Or do I have to link the complete Application to Tcl and call
> Tcl_FindExecutable(NULL) at application Startup?
> Is there a way to detect if Tcl_FindExecutable(NULL) was already called
> or has to be called again?

If the whole DLL linked against Tcl is unloaded, then obviously any
static memory area associated with it vanishes. Hence whatever is
stored by Tcl_FindExecutable is wiped.

Moreover, have a look at the Tcl_Finalize manpage. Not sure about the
"automatic" behavior mentioned there, but the manual call is guranteed
to be safe even if redundant, so I wouldn't hesitate...

-Alex

From: Don Porter on
Jens Benner wrote:
> I'm using Tcl 8.4.2 and I linked against tcl84t.lib/tcl84t.dll

Hmmm. Let me confess that my interest in your problem is whether it
demonstrates some bug in Tcl. I'm far less interested in finding a bug
in the 2003 release of Tcl than I am in finding bugs in any of the 2008
releases of Tcl. Is there no way you can use Tcl 8.4.19 or 8.5.4 ?

In another followup you gave more details about your program. It is
multi-threaded and repeatedly loads and unloads tcl.dll. I think it's
fair to say this is a under-tested mode of using the Tcl library. It's
supposed to work, but I don't know of any example I can point to to show
it working. So, it would be really helpful if you could migrate the
stress-testing you are doing to an active release of Tcl where bug fixes
might be possible (or, if we're lucky, already fixed!).

--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter(a)nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
From: Don Porter on
Jens Benner wrote:
>>> // On thread Startup
>>> TclInterp = Tcl_CreateInterp();
>>> Tcl_FindExecutable(NULL);
>>> Tcl_CreateCommand(TclInterp, "myCallback", TclCallbackCmd,
>>> (ClientData)this, (Tcl_CmdDeleteProc*) NULL);
>>> Tcl_EvalFile(TclInterp, "MySript.tcl");

> the application loads a lot of modules (dlls) via dynamically via
> loadlibrary(). In one of these modules I integrated the Tcl interpreter.
> So only this module is linked against tcl84t.lib/tcl84t.dll. The Module
> is unloaded after work and loaded again if there is work to do.
> So do I have to call Tcl_FindExecutable(NULL) every time the module is
> loaded? Or do I have to link the complete Application to Tcl and call
> Tcl_FindExecutable(NULL) at application Startup?

The value of Tcl_FindExecutable(NULL) is that it internally calls
TclInitSubsystems() which is a vital part of getting the Tcl library
initialized for all of its tasks.

The routine Tcl_CreateInterp() also internally calls
TclInitSubsystems(). So, in your example code, I believe your
Tcl_FindExecutable(NULL) calls are unnecessary, though I believe
harmless.

--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter(a)nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
From: Don Porter on
Jens Benner wrote:
> This runs fine so far for a lot of cycles but it randomly hangs up after
> several hours or days. A closer look with the debugger shows, that it
> hangs at the line TclInterp = Tcl_CreateInterp();

There is no mutex in the Tcl_CreateInterp() call itself. Does your
debugger place the hang in that routine explicitly, or could it
be nested deeper in calls that Tcl_CreateInterp() makes? If so,
what deeper routine is the one hanging?

--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter(a)nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
First  |  Prev  | 
Pages: 1 2
Prev: send command in expect
Next: working with oracle clob