[squeak-dev] About cuis 0207-AvoidCreatingDelays-jmv.1.cs

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Thu Jul 23 20:30:56 UTC 2009


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



More information about the Squeak-dev mailing list