multithreading - How do I get the same environment for a child thread in TCL? -
i using multi thread in tcl. creating thread using thread extension. send commands thread. use user defined procedures in various files. question: how make global variables main thread available child thread, without passing arguments or using thread shared variables ?
i don't know how many of variables there, , hence import them all
i tried looking environment share references environment variables shared. need whole system available child thread.
regarding libraries, able source them.
sample code
global var1 thread::create { source <library files >(has dummyproc definition) <execute statements> } thread::send "dummyproc arg1 arg2...argn" result my problem: dummyproc uses variables available in main thread (e.g. var1), while not using either tsv or pass them arguments, since there whole set of global variables.
tcl's thread support code designed around principle don't this; it's very deep assumption. each thread has own interpreters; shared state explicitly create via tsv sub-package (that's part of 8.6 documentation tree, it's not different in earlier versions). far simplest way of implementing thread put definition code in (normal!) .tcl script file , pass in instructions source when creating thread, along small bits of information need configure make particular thread doing particular task.
the plus side of this? tcl's implementation has far fewer big global locks comparable languages. (it contributed people writing production-grade commercial web servers in almost-pure tcl.)
that said, if want clone interpreter, it's not hard @ least of it. packages can loaded in other interpreter, namespaces pretty easy clone (with exception of children of ::oo various complex reasons), procedures can copied (info body, info args , info default required tools that) can global/namespace variables (especially if don't worry traces or keeping variables synchronized).
other things trickier. open channels? hard clone, impossible. object graphs tcloo? well, easier channels! tk widgets? don't try; lots of experience in other languages indicates multi-threaded guis brain-bending.
Comments
Post a Comment