The timed wait seems to be part of ns_cond: http://rmadilo.com/files/nsapi/ns_cond.html
The code I linked to earlier uses ns_cond, but without a timeout value. I have never tried to see if it works, but it seems obvious that you need more than a mutex to do a timeout operation. I believe the point of the condition is so that the process doesn't sit there spinning cpu cycles while the mutex is being waited on. I guess the timeout is an additional way to break out of a sleep state. John, you could start with my code and try to add a timeout to it. I tested this code by using a frameset to grab several tcl pages. Each page had an ns_sleep of some length. One thing my code doesn't have is re-throwing the error after a catch (as Dossy suggests), although I'm not sure if you can do this effectively. I only use catch around tiny chunks of code, and usually only so I can return or release a shared resource. Otherwise catch is usually a useless feature that makes bug fixing impossible. Instead of using catch around all the code which uses the resource protected by the condition var, I use ns_atclose to release any resources in case of an error. Example code is here: http://rmadilo.com/m2/servers/rmadilo/modules/tcl/twt/packages/db/tcl/handle-procs.tcl handle::init and handle::reset take care of it tom jackson On Thursday 22 February 2007 12:21, Nathan Folkman wrote: > For John. Just curious as to what problem the "try lock" was needed for. > > - n > > On 2/22/07, Tom Jackson <[EMAIL PROTECTED]> wrote: > > Nathan, > > > > Was this a question for me, or John? > > > > tom jackson > > > > On Thursday 22 February 2007 08:18, Nathan Folkman wrote: > > > Just curious, but what's the use case where you would use something > > > like this? > > > > > > - n > > > > > > On 2/22/07, Tom Jackson <[EMAIL PROTECTED]> wrote: > > > > I have some example code of condition wait: > > > > http://rmadilo.com/m2/servers/rmadilo/modules/tcl/twt/packages/db/tcl/dat > > > > > >asource-procs.tcl > > > > > > > > The procs lock, unlock, wait, popPool, etc. Wrap the ideas up pretty > > > > easily, > > > > > > > > but the question is what happens when you code times out waiting for > > > > a resource? > > > > > > > > tom jackson > > > > > > > > On Thursday 22 February 2007 07:09, John Buckman wrote: > > > > > I'm looking to have mutexes with timeouts, and I see support in the > > > > C > > > > > > > code for this but none carried over to Tcl. > > > > > > > > > > In the C code, there's a Ns_MutexTryLock() function, but no tcl > > > > > function for calling it. > > > > > > > > > > Ns_MutexLock calls Ns_MutexTryLock() and there appears to be > > > > > timeout support: > > > > > if (!NsLockTry(mutexPtr->lock)) { > > > > > return NS_TIMEOUT; > > > > > } > > > > > > > > > > but I don't see any way of setting the mutex timeout seconds. > > > > > > > > > > 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. > > > > > > > > > > -john > > > > > > > > > > > > > > > -- > > > > > 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. > > > > > > > > -- > > > > 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. > > > > -- > > 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. -- 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.
