Levente, i slightly modified your example to simulate interrupt
between two primitive invocations:

| sema quit result secondsWhenTick |

sema := Semaphore new.
quit := false.

[ [ quit ] whileFalse: [ sema wait.
                (Delay forSeconds: 2) wait.
                sema signal ].
                ] forkAt: Processor activePriority - 1.

secondsWhenTick := [ | lastSecond |
        lastSecond := Time primSecondsClock.
        [ lastSecond = Time primSecondsClock ] whileTrue: [ sema signal. sema
wait. (Delay
                forMilliseconds: 1) wait ]].


result := (1 to: 10) collect: [:i |
        secondsWhenTick value. [ secondsWhenTick value ] timeToRun ].

quit := true.
result

 #(2002 2002 2004 2003 2004 2004 2003 2003 2004 2004)

You know that interrupt can happen at any moment. Even if it is not VM,
it can be hardware interrupt, OS interrupt and god knows what else.

Like that we can only state: well, there is some >0 probability that
error of measurement
using #secondsWhenTick will be within ~1 msec interval.. but it is never == 1.

Which at the end means that expression:

DateAndTime now nanoSecond

and:

1000000000 atRandom

can be used more or less interchangeably, because both has nothing to
do with measurement of current system time.

-- 
Best regards,
Igor Stasenko.

Reply via email to