3 ms·
The multiple interpreters communicating by message passing model mentioned towards the end of this article as a way forward is exactly the threading model which
by cmacleod4 5y ago
The multiple interpreters communicating by message passing model mentioned towards the end of this article as a way forward is exactly the threading model which Tcl has been using successfully for the last 20 years. For more info see https://www.activestate.com/blog/threads-done-right-tcl/ https://www.activestate.com/blog/threads-done-right-tcl/ and https://www.tcl.tk/man/tcl/ThreadCmd/thread.html#M44 https://www.tcl.tk/man/tcl/ThreadCmd/thread.html#M44 .
- celeritascelery 5y agoAre tcl functions shared between threads? Or does each new thread interpreter start from a clean state?
- cmacleod4 5y agoFunctions (procs) and other state are not shared between interpreters. So they do need to be reinitialised in each thread. This is not hard to do though. The messages which can be passed between threads can be arbitrary scripts to be executed in the target interpreter, such as proc definitions.
- blacksqr 5y agoThe Tcl thread library allows you to create multiple threads in a single interpreter, and use mutexes. locks etc. to manage them. In this case of course you only need to initialize your interpreter once. The library is most used in an "easy" mode however, where each thread starts up with its own interpreter and thus the usual mutex/lock dance is unnecessary. Various forms of message passing can be done among these interpreters, including tools provided by the thread library itself, Tcl's built-in synthetic channel feature which makes communication look like standard file I/O, or, since each interpreter has its own event loop, Tcl's socket I/O features can be used to set up server/client comms.