On 2007.02.22, John Buckman <[EMAIL PROTECTED]> wrote:
> It's trivially simple to modify NsTclMutexObjCmd (in tclthread.c) to  
> support "ns_mutex try" and I'm wondering if there's a reason this  
> hasn't been done.

My guess is because nobody actually needed it, yet.

I'd implement it as ns_mutex trylock to avoid any confusion with the
word "try" possibly implying "try/catch".

Should also get around to implementing "ns_mutex eval $mutex
$script"--acquire the mutex, evaluate the script, release the mutex.
Catch any Tcl errors and re-throw them.  This guarantees that the mutex
is unlocked, which avoids the trivial deadlock case:

    ns_mutex lock $mutex
    ... some bad code that throws uncaught Tcl error ...
    ns_mutex unlock $mutex

As the uncaught Tcl error causes execution to stop, the "ns_mutex unlock"
doesn't happen.  "ns_mutex eval $mutex $script" is simply shorthand for:

    ns_mutex lock $mutex
    set err [catch $script]
    set savedInfo $::errorInfo
    ns_mutex unlock $mutex
    if $err { error $::savedInfo }

Perhaps not exactly that, but something relatively similar in purpose,
anyway.

-- Dossy

-- 
Dossy Shiobara              | [EMAIL PROTECTED] | http://dossy.org/
Panoptic Computer Network   | http://panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to