- Tcl and threads
- Tcl Benchmarks with Threads
- Threads vs. events
- Sew what - a discussion of Tcl and threads
- The thread extension package
Threading is "fault-prone, deadlock-prone, priority-inversion-prone". Lock (mis)management makes it poor in scaling. It's hard to reason about thread behavior [justify].DKF wrote in the comp.lang.tcl newsgroup:
- "When I deal with threading, I work on the principle that the hardware and OS are my enemies and hate me, and so I code accordingly. It probably doesn't make for a maximally-efficient program, but it does reduce debugging pain."
- I reckon it is easier to think about this whole business like this: Processes contain threads (at least one) and threads contain interpreters (at least one.) The current directory is a process-resource, just as the call-stack is a thread-resource (Note that variables on the stack are *also* interpreter-resources.) and commands are interpreter-resources. Interpreters may be either safe or unsafe, and the master interpreter for each thread is always unsafe. IIRC, cd is an untrusted command by default (i.e. it is up to the master to decide whether to provide a vetted version of it.)
- I operate (even in much more controlled situations than what's being considered in this thread) by never writing code that depends on the current directory, effectively assuming that after the first bit of the startup process the value of pwd can vary wildly. Luckily, file join makes it easy, even when the code is meant to be cross-platform.
Much more deserves to be Wikified. Consider, for example, these comments of Joe English: "And David Gravereaux' advice is worth repeating: making extensions multi-interp safe goes a long way towards making them thread-safe.I find it easiest to make extensions multi-interp safe and thread-oblivious: if you avoid global and static variables, keeping all the extension's internal data in a per-interp data structure, you can often avoid locking altogether."
RS: "Threads are for hangmen ;-)"
Alan Cox (reputedly): "A computer is a state machine. Threads are for people who can't program state machines."
KBK (21 June 2003) Even the designers of Java, where threads are ubiquitous, appear to have been distinctly ambivalent about them. From :
- Use of threads can be very deceptive. In many cases they appear to greatly simplify programming by allowing design in terms of simple autonomous entities focused on a single task. In fact in some cases they do simplify design and coding. However, in almost all cases they also make debugging, testing, and maintenance vastly more difficult and sometimes impossible.
See also http://www.tcl.tk/doc/howto/thread_model.html - Tcl Threading Model.
UK (26 Sept. 2006) This link was mentioned on c.l.t with a disemination of threadability of different scripting languages: http://article.gmane.org/gmane.comp.web.aolserver/13391