2009/1/21 Panicz Maciej Godek <[email protected]>:
>
> I expect that, after reaching the maximum count (the range of int), the timer
> twists back to zero, instead of growing boundlessly.
>
> In that case, the following code may fail:
>
> (define (for-ticks-pass-time-left ticks operation)
>  (let ((total-ticks (+ ticks (get-internal-real-time)))
>        (elapsed-ticks 0)
>        (current-ticks 0)
>        (processed-ticks 0))
>    (while #t
>      (set! current-ticks (get-internal-real-time))
>      (set! elapsed-ticks (+ elapsed-ticks (- current-ticks processed-ticks)))
>      (set! processed-ticks current-ticks)
>      (if (>= elapsed-ticks total-ticks)
>        (break))
>      (operation (- total-ticks elapsed-ticks)))
>    (- elapsed-ticks total-ticks)))

Thanks for explaining.  In terms of the libguile Scheme API, it seems
to me that there isn't currently a good answer to this.  Either we
should implement (get-internal-real-time) such that it doesn't wrap -
which it doesn't look like we do currently - or we should provide
another primitive to indicate what the maximum (and hence wrapping)
value is.

(It may in practice be most-positive-fixnum, but Scheme code shouldn't
have to assume that.)

If you're getting into C code anyway, would you be interested in
writing a libguile patch for this?

Regards,
        Neil


Reply via email to