W3C home > Mailing lists > Public > www-voice@w3.org > July to September 2009

[SCXML] Algorithm mainEventLoop and the internalQueue

From: Philipp Kolhoff <philipp.kolhoff@googlemail.com>
Date: Mon, 27 Jul 2009 21:55:00 +0200
Message-ID: <4A6E0614.8030701@googlemail.com>
To: www-voice@w3.org
(Sorry for duplicates, I did not use my registered email before)
Hi there,
I've been working with Statecharts and esp. SCXML for a longer time now. 
I started implementing an interpreter in C# and C++ first for my 
Diploma-Thesis, which got then published in "Game AI Wisdom 4" and later 
found use in my companies Point&Click-Adventure Engine. Now i started to 
work on an interpreter written in ActionScript to get a library that any 
Flex developer can slap into her RIA/game. So when I came back I found 
the description of the Algorithm for interpreting SCXML's and that was a 
great help to re-implement my interpreter.
However I stumbled upon a part in the mainEventLoop after implementing 
it and running some Test-SCXML's... maybe I did not get it right, but I 
think there maybe a mistake:

Take a scxml snipplet like this:

<parallel id="InTest">
 <state id="s1">
        <transition target="s11"/>
     <state id="s11"/>
     <final id="s12"/>
 <state id="s2">
        <transition target="s21"/>
     <state id="s21"/>
     <final id="s22"/>
 <transition event="InTest.Done" target="f"/>


// now take any newly enabled null transitions and any transitions 
triggered by internal events
macroStepComplete = false;
    enabledTransitions = selectEventlessTransitions()
    if (enabledTransitions.isEmpty()):        internalEvent = 
internalQueue.dequeue()// this call returns immediately if no event is 
       if (internalEvent):
          datamodel.assignValue("event", internalEvent)
          enabledTransitions = selectTransitions(internalEvent)
           if (enabledTransitions):
       macroStepComplete = true

Suppose during the execution of an external event more than one internal 
event is queued. This happens often if a parallel-state is "Done" and 
its children are as well. In the case listed above, there would be 
generated the events s1.Done, s2.Done and InTest.Done in that order (if 
proper transitions would exist and the events would be fired). During 
the next macro step, the first internalEvent is dequeued ("s1.Done"), 
but no transition will be enabled. That would mark the macroStep as 
complete and no other internal event is handled until the next external 
event is dispatched.
Imho, there should be done something like this more likely:

if (enabledTransitions):
  macroStepComplete = internalQueue.isEmpty()

So, if the internalQueue is not empty, the macrostep will dequeue the 
next event in the internal queue.

Any opinions?

Best regards,
Philipp Kolhoff
Received on Tuesday, 28 July 2009 08:43:15 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:07:40 UTC