[ Previous ] [ Contents ] [ Index ] [ Next ]

ns_share

Overview

Share variable among all Tcl interpreters

Syntax

ns_share -init {initscript} variable ...

Description

Makes the specified variable(s) available to all Tcl interpreters in a virtual server. Normally, variables are only available to the current Tcl interpreter, unless the SharedGlobals parameter is On. Multiple variables can be specified by separating the variable names with spaces:

    ns_share count length width

You can optionally specify an init script when you share a single variable (not when sharing multiple variables). The following example sets the variable count to 0 immediately after sharing it, and the next line increments it to 1:

    ns_share -init {set count 0} count
    incr count

You can initialize shared arrays like this:

    ns_share -init {
      set itemlist(a) "Value 1"
      set itemlist(b) "Value 2"
    ) itemlist

Unlike global variables, shared variables are not available by default at the global level. You must share a variable at the top level also and not just in procedures that want to reference the variable. For example:

    ns_share pagelength
    set pagelength "50"
    proc page { conn i } {
      ns_share pagelength
      ...
    }

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1996 America Online, Inc.