John, nearly all the nsv_* and ns_thread work you need to do, plus more, has
already been done. Check outZoran Vasiljevic's 2.4 release of the Tcl
Thread Extension:
I looked over the Tcl Thread Extension docs and release notes back in
August, but did not actually review the code or try it out.
Basically, it sounds a lot like AOLserver's ns_thread and nsv souped
up, made more general and powerfull.
E.g.: "thread::send passes a
script to another thread", which is something I currently do in
AOLserver using ns_cond and an nsv to hold lists of Tcl code to eval.
All the tsv:* thread shared variable stuff, like nsv_* but with
additional usefull atomic commands like lreplace, lpop, lpush. It
apparently does some fancy manipulation of Tcl 8 objects for the sake
of efficiency, rather than only using strings. Etc.
And, the release notes say it supports use both as a tclsh
and an AOLserver 3.x loadable module. Sounds fabulous!
As far as I know, no one is actually using the Tcl Thread Extension in
AOLserver yet, but it would make sense to do so, and I'm told the AOL
crew thinks that might be feasible and/or good somewhere down the
road.
And of course, for your purposes, emulating nsv on top of the Thread
Extension's new tsv:: stuff should be trivial, as tsv does everything
nsv does plus more.