|
Boost Users : |
Subject: Re: [Boost-users] [StateChart] event processing order in async machine
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2010-10-20 07:14:11
Hi Igor
As far as I can tell, the phenomenon you're observing would maifest itself in
the same way in synchronous machines as it does in your async machine. What
follows therefore only considers the properties that are common to both types
of machines.
The mechanisms involved here are the following:
1. Each state machine has a general event queue.
2. Logically, there is a *per-state* deferred event queue, which stores
incoming events that are deferred while the machine resides in a given state.
Whenever a state is left, all deferred events for that state are moved into
the general event queue.
3. As the last step of state_machine::process_event, all events in the general
event queue are processed.
IIUC, what you're observing can be explained with the 3 points above, right?
In your example, When s1 is left, instances of ev3to4_1 and ev3to4_2 are moved
from the deferral queue to the general event queue, although the next state
does nothing else but defer them also. IMO, the root of the problem lies here.
A better solution would be to put both s1 and s2 into an outer state (e.g. s)
and have that defer ev3to4_1 and ev3to4_2. s1 would then only defer ev2to3 and
transition to s2. Similarly, s2 would then only transition to s3.
This does away with some duplication in your code (the deferral of ev3to4_1
and ev3to4_2 in both s1 & s2) and would also be slightly more efficient, as
the deferred events are only put into the general event queue exactly once
(when s is left).
HTH & Regards,
-- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net