Am Dienstag, 16. Dezember 2014, 08:31:39 schrieb Anton Ertl: > On Mon, Dec 15, 2014 at 10:45:09PM +0100, Bernd Paysan wrote: > > BTW: Modern OSes support nanosecond sleeps, > > so what about having : ms ( n -- ) 1000000 m* ntime d+ ns ; and putting in > > the actual replacible sleep logic into ns? > > > > Actually, the right spec is to define an absolute deadline instead of a > > relative; we should do that with ns (ANS/Forth200x failed with MS); maybe > > the name might need to change (ABSTIME-NS? DEADLINE-NS?). > > DEADLINE sounds good. One would naturally use it with UTIME (or > something like it), so either we make DEADLINE accept microseconds, or > we add NSTIME to produce nanoseconds.
I've already added NTIME ( -- d ); the consensus between different API makers seems to be that a nanosecond is a good unit, even though current CPUs and OSes don't even deliver microsecond accuracy for waiting, and take nearly half a microsecond for reading out the timer... but that might change. > My guess is that the idea is that there are usually no threads that > wait for both an absolute deadline and some other event; so threads > that wait for an absolute deadline, use pthread_cond_timedwait(), > others use select() or poll() or something. No, unfortunately, the typical case is that you wait for an event *and* have a deadline. Typically, you want to wait for the deadline, but you need to respond e.g. to inter-task communication, too, or accept other asynchronous stuff. > We can implement the absolute timeout with a relative one: > : deadline ( d -- ) > > utime d- dup 0> if us else 2drop then ; > > where US ( d -- ) is a microsecond variant of MS. Yes. > Are we in the word-savers club? That's as idiotic as F~. Such > trickery is only justified if we want to reconcile two existing > conflicting usages of NS, but that's not the case here. Just have NS > (or US) for relative deadlines (analogous to MS), and DEADLINE for > absolute ones. Ok. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/