"Tobias C. Rittweiler" <tcr@...> writes:
> I was bitten by the fact that deadlines work with millisecond
> granularity. My guess is that the following patch could make people
> quickly aware of this constraint because they'll most likely encounter
> it when playing at the repl.
> Anyone mind?
> --- deadline.lisp.~1.5.~ 2010-01-22 20:21:16.000000000 +0100
> +++ deadline.lisp 2010-02-17 01:24:37.000000000 +0100
> @@ -25,7 +25,8 @@
> (truncate (* seconds sb!xc:internal-time-units-per-second)))
> (defmacro with-deadline ((&key seconds override)
> - &body body)
> + &body body
> + &environment env)
> "Arranges for a TIMEOUT condition to be signalled if an operation
> respecting deadlines occurs either after the deadline has passed, or
> would take longer than the time left to complete.
> @@ -38,7 +39,16 @@
> not extended. Deadlines are per thread: children are unaffected by
> their parent's deadlines.
> +Caveat: SECONDS is interpreted with millisecond precision, only.
> + (when (constantp seconds env)
> + (let ((secs (constant-form-value seconds env)))
> + (assert (numberp secs) ()
> + "~S passed for :SECONDS which is not a number." secs)
> + (unless (zerop (nth-value 1 (truncate secs 1e-3)))
> + (style-warn "~@<WITH-DEADLINE operates on milliseconds, but ~
> + was used with :SECONDS ~A.~@:>" secs))))
> (with-unique-names (deadline-seconds deadline)
> ;; We're operating on a millisecond precision, so a single-float
> ;; is enough, and is an immediate on 64bit platforms.
Richard Goldman just reminded me of the perils of floating point
arithmetics, and that ZEROP is too strict here. I don't really feel like
messing with FP for the days comming, so I'll probably leave it as is.