In a message dated 11/10/2002 3:09:41 AM Eastern Standard Time, [EMAIL PROTECTED] writes:

The 7.6 ns_share was a *deep* hack into the Tcl internals. It is
difficult to understand and maintain. Just look at all these locks arround!
Locks in one function, unlocks in other. Brrr... One gets lost pretty fast.
Benefits?




Zoran's right - the 7.6 ns_share code was a "deep" hack.  Here's a comment in tcl7.6/generic/tclVar.c I wrote years ago about how it works:

       /*
        * The Var structure has an Ns_Mutex pointer which if not null is
        * locked in LookupVar and unlocked later when safe.  This is a
        * poor programming style - locking and unlocking at different
        * procedure levels - but's it's necessary with all the weirdness
        * that LookupVar does.  If the shared variable is an array the
        * lock is shared for the whole array.  Note that to avoid even more
        * craziness the shared Var structure refCount is set to 1 instead
        * of 0 here to ensure it is *never* actually deleted,
        * even if the contents (array or scalar) are.  This means this is
        * a memory and lock leak:
        *
        *    set n 0 ; while 1 {ns_share $n ; set $n 1 ; unset $n}
        */


Oh well.  Briefly, this is how we got here from what I can remember:

Naviserver 1.0 - Tcl7.3 single threaded, no shared vars that I can remember

Naviserver 2.0 - Tcl7.4 hacked for thread safety only, shared data with the simple "ns_var" command (still exists)

AOLserver 2.1 - Tcl7.4 Severly hacked (much more than what you see in 7.6) to share nearly everything.  Basically, the Tcl interp was split into private and shared parts - the shared parts included the Tcl command/proc tables and the global variables.  Yes - all global variables, not special shared variables, which meant simple things like the global errorInfo didn't work right

AOLserver 2.2->2.3 - Shared globals now an option (off by default) and ns_share introduced.  The Tcl7.4 core was further hacked to distiguish between local, global shared, global private, and the new shared vars. 

AOLserver 3.0 - Tcl 7.6 code hacked for thread safety and to support the ns_share command only.  3.0 came out around the same time as 8.1.  People were asking for 8.1 so I looked at hacking the 8.1 var code as was done in 7.6.  This turned out to be hard - I couldn't isolate all the changes to tclVar.c because, for example, variables now showed up in literal tables as part of byte compiling and such.  Anyway, we wanted to stop hacking the Tcl core going forward.  To cover existing use of ns_share, Brent Welch from Scriptics wrote a variable trace version.  It worked but wasn't as efficient as the direct support in 7.6.

AOLserver 3.4 (maybe earlier?) - Added the nsv interface.  This was based on some of the command-based shared data interfaces we had created at AOL.

So, seems like the variable tracing ns_share in AOLserver 3.x and 4.0 could be used as a basis to extend nsv but it may not approach the performance of the 7.6 shares.  If ns_share is really very useful, perhaps the TIP process could be used to consider adding support in the Tcl core.

-Jim

Reply via email to