starkit-lite and threads: can't package require

55 views
Skip to first unread message

Uwe Koloska

unread,
Jul 12, 2007, 7:55:05 AM7/12/07
to starkit
Hello,

the current tclkit-lite builds (by means of kbs) cannot load any packages
inside a thread.

1. the auto_path is not promoted, but I think this is intentional
2. the vfs-filesystem is not known inside the thread
3. the pkgIndex.tcl files alongside the auto_path dirs are not loaded inside
the thread

My first workaround for 3. with an unpackaged vfs was to explicitly load the
required pkgIndex.tcl (for I only use one package inside the thread). But
this doesn't work in the starkit nor in a starpack.

I vaguely remember some discussion, but don't remember where and with what
subject, that the initialization code for interpreters is flawed in
tclkit-lite. Is there a fix or someone working at it? Where do I have to
start, to make a fix myself?

Sincerly
Uwe Koloska

--
Dipl.-Ing. Uwe Koloska

voice INTER connect GmbH Tel +351 481 088 3
Ammonstraße 35 Fax +351 438 399 25
01067 Dresden - Germany www.voiceinterconnect.de

Uwe Koloska

unread,
Jul 15, 2007, 7:41:18 PM7/15/07
to starkit
Hello again,

On 12 Jul., 13:55, Uwe Koloska <kolo...@voiceinterconnect.de> wrote:
> I vaguely remember some discussion, but don't remember where and with what
> subject, that the initialization code for interpreters is flawed in
> tclkit-lite. Is there a fix or someone working at it? Where do I have to
> start, to make a fix myself?

I have found this discussion: It is an old thread on this list
starting on 2007-01-02 with the subject "starpack vfs can't be
accessed from thread". But the fix that is presented by Jeff Hobbs
ist already included in the boot.tcl and the provided threadvfs
procedure that starts a new thread with the vfs mounted doesn't work
-- maybe because it was not meant for a starkit-lite without a proper
mk4 database engine.

What I understand now, ist that it is by intention, that a thread has
not the same vfs mount then the main thread.

But what is the recommended way to load a package inside a thread?

The only reason I have to use threads (yes, I know the discussion
about threads, being evil ;-) is a c-based package (fluidsynth, if you
care) that uses threads, because callbacks from this thread create big
troubles, if they used to trigger Tk functions -- but this is another
story and told inside another discussion ;-)

Sincerly
Uwe Koloska

Pat Thoyts

unread,
Jul 16, 2007, 5:33:22 PM7/16/07
to Uwe Koloska, starkit

There are some issues still with the initial startup code. Its been a
while but if I remember correctly I found the internal packages were
not always available in slave interpreters and this is likely the same
in thread interpreters. I currently use a modified kitInit.c as
attached. This drops the preInitScript in favour of using the full
appInit script as was done in the old tclkits. Possibly this will help
you -- seems to work ok for me.
Pat Thoyts

kitInit.c.patch

Uwe Koloska

unread,
Jul 16, 2007, 7:41:24 PM7/16/07
to sta...@googlegroups.com
Hello,

Am Montag, 16. Juli 2007 schrieb Pat Thoyts:
> There are some issues still with the initial startup code. Its been a
> while but if I remember correctly I found the internal packages were
> not always available in slave interpreters and this is likely the same
> in thread interpreters. I currently use a modified kitInit.c as
> attached. This drops the preInitScript in favour of using the full
> appInit script as was done in the old tclkits. Possibly this will help
> you -- seems to work ok for me.

Yes, this works. At least the internal packages are available. But the vfs
is still not mounted (I think this is due to the thread safety problem). A
simple
package require starkit
starkit::startup
doesn't mount the vfs (or at least not with the same path).

How can I load packages from the vfs inside the thread?

The threadvfs proc from the earlier mentioned thread doesn't work anymore.

Thank you for any help
Uwe Koloska

Hermann Boeken

unread,
Aug 21, 2012, 10:19:46 AM8/21/12
to sta...@googlegroups.com
Hello Uwe,

have you ever found the solution to this problem?
I have a similar problem here.
I want to package a threaded application as starpack, but none of my threads have access to the Tcl packages within the app's vfs then.

//Hermann

Hermann Boeken

unread,
Aug 22, 2012, 4:26:54 AM8/22/12
to sta...@googlegroups.com, Uwe Koloska

Hello Pat,

is there also a patch available for the current version of kitgen (patthoyts-kitgen-273ad4c)?

//Hermann

Uwe Koloska

unread,
Aug 24, 2012, 8:12:56 PM8/24/12
to sta...@googlegroups.com
Hello Hermann,

Am Dienstag, 21. August 2012 schrieb Hermann Boeken:
> have you ever found the solution to this problem?

At least I have found something that works for my app -- YMMV!

> I have a similar problem here.
> I want to package a threaded application as starpack, but none of my
> threads have access to the Tcl packages within the app's vfs then.

Here is my version of the thread init-function that does the trick for me:

#+BEGIN_SRC Tcl
package require Thread
proc threadvfs {} {
if {[info exists starkit::mode] && $starkit::mode ne "unwrapped"} {
set self $starkit::topdir
append data "vfs::mk4::Mount \"$self\" \"$self\" -readonly\n"
}
append data "set ::auto_path [list $::auto_path]\n"
append data "thread::wait"

return [thread::create $data]
}
#+END_SRC

Hope this helps
Uwe

Hermann Boeken

unread,
Aug 29, 2012, 5:19:12 AM8/29/12
to sta...@googlegroups.com
Hello Uwe,

I tried your solution and it looks promising.
A first test was successful.

Thanks for sharing your solution,
Hermann
Reply all
Reply to author
Forward
0 new messages