Torbjörn Lager wrote:
Dear All, In an application that I'm writing I need a way to 'block' computations for very short periods of time. I thought at first that Delay would do the job, but runningfor I in 0..1000;10 do T1 T2 in T1 = {Property.get 'time.total'} {Delay I} T2 = {Property.get 'time.total'} {ShowInfo I#'\t'#T2-T1#'\t'#{Int.toFloat (T2-T1)}/{Int.toFloat I}} end shows that (at least under Windows) results of calls to {Delay I} aren't very precise: {Delay 10} delays for 16 ms, {Delay 20} for 31 ms, {Delay 100} for 109 ms, etc. See the table produced by the above code at theend of this message. (On the other hand I've noticed that I do get exact times for {Delay I} when I are multiples of 125 - if that's by coincidence, I don't know..?. )Now, I've read about Delay in CTM and I think I understand the above behaviour. {Delay I} suspends the calling thread T for *at least* I ms, and when T is allowed to run again, it is subject to the ordinary thread scheduling mechanism, which means that it may take a bit longer to actually run. So I guess Delay does what it is supposed to do. The fact remains that I need timing more exact than that though, so here are my questions: - Is it possible to write a version of Delay which is more exact for small Is? - Is there anything else that I can use? {MyDelay I} does not necessarily have to suspend the calling thread - it can just eat cycles from it - not too many though... - Is the exactness of {Delay I} when I are multiples of 125 something I can rely on? Cheers, Torbjörn
As I understand it, the implementation of Delay depends on the timing interrupts in your operating system, so the large granularity is rather deeply built into the system. Shorter times just can't be measured by the operating system. But maybe what you want is just an *ordering* of events, independent of the time they take? In that case, instead of using Delay, maybe you can just use a priority queue. Just suspend the current thread on a dataflow variable and put it in the priority queue together with the "time" that it should be allowed to continue. Peter _________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
