+---------- On Jan 27, Seena Kasmai said:
> sorry, there is no $ sign in the actual code.
>
> So, is it worth trying to substitute ns_share with nvs stuff (nsv_set &
> nsv_get) to see if the problem goes away ?

Your most effective action, if you want to maximize the utility of
the advice from this mailing list, would be to create a test case
that reproduces the problem, and post it in its entirety. Posting a
"simpified" version of your problematic production code is not very
helpful, because the simplified version is likely to omit whatever is
causing the problem.

That said, I doubt that using nsv_* instead of ns_share will help.
Given your description of the problem, the most likely cause is that
an error is occurring in a critical section (a section where the mutex
is locked), preventing the Tcl interpreter from reaching the "ns_mutex
unlock" command. You have not yet proved to us that this is not the
case.

So the next logical step (other than creating a test case) is to test
the hypothesis that such is the case, by putting catch commands around
your critical sections. For example, suppose the critical section looks
like this:

    ns_mutex lock L
    SCRIPT
    ns_mutex unlock L

Then you should change that to this:

    ns_mutex lock L
    set code [catch {
        SCRIPT
    } result]
    ns_mutex unlock L
    if {$code != 0} {
        return -code $code -errorinfo $::errorInfo \
            -errorcode $::errorCode $result
    }

(You'll need to use different variable names if you already have
variables named "code" and "result".) You can see that this guarantees
that L will be unlocked, no matter what happens when SCRIPT is executed.

Another approach would be to create a procedure like this:

    proc ns_mutex_eval {lock script} {

        ns_mutex lock $lock
        set code [catch {uplevel 1 $script} result]
        ns_mutex unlock $lock

        return -code $code -errorinfo $::errorInfo \
            -errorcode $::errorCode $result
    }

Then you would change the example critical section above to this:

    ns_mutex_eval L {
        SCRIPT
    }

This way you don't have to worry about reusing the variable names "code"
and "result", and you don't have to repeat as much code at each critical
section.

Reply via email to