Re: starpack vfs can't be accessed from thread
| Newsgroups | gmane.comp.lang.tcl.starkit |
|---|---|
| Message-ID | <011120070129.12423.45A592E0000C0E2C000030872213575333089C0E099D0E099C@comcast.net> |
-------------- Original message ---------------------- From: [email protected] > Unless I'm missing something, it seems that there's a chicken and egg problem. > In order to mount the vfs in the child thread, I need also to "package require > vfs::mk4", yet I can't require that package until after I've mounted the vfs. > I created a script that will launch a thread with the appropriate things initialized to be able to access a starpack's vfs from the new thread. However, while this enables the thread to access the vfs, the package mechanism does not find packages inside the vfs from within the new thread. If you cd into the directory directly, files can be "source"'d from the thread so the vfs is (sort of) working. I'm setting the auto_path variable for the thread, is there anything else that's necessary to get the package mechanism to work? Also, while this sort of works, it's fairly fragile. Occassionally the starpack will die, and it dies in a strange way (on windows). The application throws up one of the "This application has had an error. Debug/Close" dialogs, yet after selecting close, the application will pop back up only now its pwd is C:/Windows/System32. This is the similiar behavior to what I would see in the thread-unsafe version (8.4.13) when it crashed. Perhaps there's still something in the vfs code that's not thread-safe? Here's the script: package require Thread proc threadvfs {} { # get the vfs & vfs::mk4 procs set data "load {} vfs\nload {} rechan\n" foreach proc [info procs vfs::*] { append data "proc $proc [list [info args $proc]] [list [info body $proc]]\n" } # HACK: The vfs::mk4 package ifneeded body is a single "source" # statement, so read the file. This will break if the vfs::mk4 # package ever changes. set file [open [lindex [package ifneeded vfs::mk4 [package present vfs::mk4]] 1] r] append data [read $file] "\n" close $file append data "vfs::mk4::Mount [info nameofexecutable] [file tail [info nameofexecutable]] -readonly\nset ::auto_path [list $::auto_path]\nthread::wait" return [thread::create $data] }