[Cuis-dev] Strange behavior with stepping

Gerald Klix cuis.01 at klix.ch
Sat Aug 21 06:04:37 PDT 2021


Hi Hilaire,

I only did a short static analysis
(a fancy word for looking at the code
and scratching your head).

IHMO there's a race condition:

WorldMorph>>#runLocalStepMethods

	| stepMessage |
	[ stepList notEmpty and:
            [ stepList first scheduledTime <= nowTime ]]
		whileTrue: [
			stepMessage _ stepList first.


This piece of code looks at the scheduleTime of the
heap's first element then actually retrieves
the first element.
While this happens the heap in stepList may
be changed by adding or removing elements.

Please try the attached method and tell me if it helps.

@Juan: Even if my change does not fix Hilaire's problem
the method should still be changed.


HTH,

Gerald


On 8/21/21 1:14 PM, Hilaire Fernandes via Cuis-dev wrote:
> Hi,
> 
> In DrGeo there is this user interaction to let the user easily merges 
> two points: the user moves one point over another one to merge with, 
> then holds for 1500 milliseconds for the merging operation to take place.
> 
> It is done with stepping:
> 
> restartMouseStillDownHandle         self startStepping: 
> #processMouseStillDown             in: 1500             stepTime: 1]
> 
> The problem is the mouseStillDown message is called immediately not 
> after 1500 milliseconds.
> 
> Looking at step code below, is the at: argument right? Tried with Time 
> millisecondClockValue (as coded with Pharo), the effect is the same:
> 
> startStepping: aSelector in: millisecs stepTime: stepTime     "Start 
> stepping the receiver"     self world ifNotNil: [ :w |         w     
> startStepping: self             at: Time localMillisecondClock + 
> millisecs             selector: aSelector             stepTime: stepTime]
> 
> Any clue?
> 
> Thanks, best
> 
> 
-------------- next part --------------
'From Haver 5.0 [latest update: #4782] on 21 August 2021 at 2:59:24 pm'!

!WorldMorph methodsFor: 'stepping' stamp: 'KLG 8/21/2021 14:59:15'!
runLocalStepMethods: nowTime
	"Run morph 'step' methods (LOCAL TO THIS WORLD) whose time has come. Purge any morphs that are no longer in this world."

	| stepMessage |
	[ stepList notEmpty and: [ (stepMessage _ stepList first) scheduledTime <= nowTime ]] 
		whileTrue: [
			(stepMessage receiver shouldGetStepsFrom: self)
				ifFalse: [ stepList removeFirst ]
				ifTrue: [
					stepMessage valueAtTime: nowTime.
					stepMessage rescheduleAfter: nowTime.
					"We've just updated the  scheduled time for stepMessage.
					It might have been that stepMessage was removed altogether from stepList.
					It also may be the case that stepList got added or removed other elements while on #valueAtTime:
					Just reSort. It will be ok in any case."
					stepList reSort.
					]
		]! !


More information about the Cuis-dev mailing list