Hi Nicolas,
Nicolas Cellier wrote:
> Hi Juan,
> In Cuis i noted this method to avoid creating Delays in tight loops:
>
> interCyclePause: milliSecs
> "delay enough that the previous cycle plus the amount of delay will
> equal milliSecs. If the cycle is already expensive, then no delay
> occurs. However, if the system is idly waiting for interaction from
> the user, the method will delay for a proportionally long time and
> cause the overall CPU usage of Squeak to be low."
>
> | currentTime wait |
> waitDelay ifNil: [ waitDelay _ Delay forMilliseconds: 50 ].
> Preferences serverMode
> ifFalse: [
> (lastCycleTime notNil and: [CanSurrenderToOS ~~ false]) ifTrue: [
> currentTime _ Time millisecondClockValue.
> wait _ lastCycleTime + milliSecs - currentTime.
> (wait > 0 and: [ wait <= milliSecs ] )
> ifTrue: [
> waitDelay setDelay: wait; wait ] ] ]
> ifTrue: [ waitDelay wait ].
> lastCycleTime _ Time millisecondClockValue.
> CanSurrenderToOS _ true.
>
>
> It seems to me that if you switch Preferences serverMode to true, then
> the waitDelay duration will be undetermined instead of being 50ms.
> Unless there is some special code to reset the waitDelay to nil that
> I'am not aware of...
> What do you think?
>
> Nicolas
>
You're indeed right! You found a bug. Thanks!
The correct code is
ifTrue: [ waitDelay setDelay: 50; wait ].
This will be in the next Cuis release.
Cheers,
Juan Vuletich