Re: revised mainEventLoop

Le 8 mar 2013 à 13:57, Jim Barnett a écrit :

> David,
> The intent is that eventless transitions always take priority, so we test them first each time around the loop.  For example, suppose we take a transition from S1 to S2 on internal event e.  The first thing we do in S2 is test for eventless transitions.   Even though there were no eventless transitions enabled in S1 (if there were, we would have taken them instead of dequeuing e), there may be new ones enabled once we reach S2.  S1’s onexit handlers, the executable content in the transition, or S2’s onentry handlers may all have modified the datamodel.  (The most obvious use case would be an onentry handler that counts how often you have  entered the state with eventless transitions providing special behavior based on the count.)


I understand that but fail to see how testing eventless transitions first, but once, at the beginning of the loop, would not accomplish it.
As in:

while running and not macrostepDone:
	// try eventless first
	enabledTransitions=selectTransitions(null)
	if enabledTransitions is empty:
		// consume internal events until one matches something
		while (event=internalQueue.dequeue()):
			datamodel._event=event
			enabledTransitions=selectTransitions(event)
			if enabledTransitions is not empty: break
	if enabledTransitions is empty:
		macrostepDone=true
	else: microstep(enabledTransitions)

If an internal event doesn't match any transition, the configuration won't change, nothing is exited or entered. Targetless transitions aren't going to be enabled by simply consuming a new event unless they were testing _event in their condition.

			David

Received on Friday, 8 March 2013 16:52:02 UTC