[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: coroutines & timeout
- From: Doug Rogers <rogers@...>
- Date: Wed, 14 Apr 2004 07:48:53 -0400
On Tuesday 13 April 2004 17:13, wiffel@yucom.be wrote:
> I would be happy with a version of 'coroutine.resume' that can time-out.
I'm curious how that would be implemented without building a threading library
into the VM. I, too, would be very happy to have that sort of behavior
available for my embedded work.
> As a test I fooled around in the VM and hacked a bit around to see if
> such a construct is at all possible. I added a primitive called
> 'coroutine.timedresume' that behaves as the 'coroutine.resume' but takes
> as it's second parameter a number which represents the milliseconds
> after which a 'yield' should be 'forced'.
Do you happen to have a patch of that change? I'd love to check it out. What
do you do with the (not-fast-enough-) yielding code? What mechanism do you
use to stop that code? I suppose a better understanding of the VM on my part
- and a copy of your patch! - would help me.
I think using an absolute timeout, like pthread_cond_timedwait(), is
preferable. Of course that requires a standard monotonic time source. Or
perhaps provide for both absolute and relative times; something like
coroutine.resumeuntil and coroutine.resumeduration.
One of the things that bugs me about the use of timespecs in C is that the
POSIX clock_gettime() is NOT monotonic - it is allowed to follow the system
time, which can be set from outside the running program. That means that
either the realtime code must manage the changes reasonably or that it must
use a separate clock. In our case, we just never set the time on our system.
It's typically January 1970 whenever you ask it!
Yours in curiousity,
Doug Rogers