On Mon, Jan 27, 2003 at 12:23:50PM -0600, Rob Mayoff wrote:

> 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

This is good advice, and not just for debugging!  When I run ANY with
a mutex locked that could ever possibly error out, I always wrap it in
a catch to properly clean up the mutex on error.  E.g.:

ns_mutex lock $data_mutex
if { [catch {
   error "Foo!"
} errmsg] } {
   # We caught an unexpected error while the mutex was locked, so
   # unlock the mutex, then re-throw the error:
   ns_mutex unlock $data_mutex
   global errorInfo
   set my_error $errorInfo
   error $my_error
}
ns_mutex unlock $data_mutex

--
Andrew Piskorski <[EMAIL PROTECTED]>
http://www.piskorski.com

Reply via email to