I am currently researching Hierarchical State Machines (UML State Machines, Statecharts, etc.), and the following is unclear to me:
Is pushing events to machine's own event queue during transitions and from states valid, and if it is, is it safely used in practice or should it be avoided? Are there certain implications when doing this (implementation quirks at least, problems when orthogonal regions come into play, or similar)?
I will illustrate the question with two dummy machines:
the following machine would be in state
A
waiting for eventA_to_B
, after which it'd get into infinite loop by dispatching events as transition actions:+-----+ +-----+ +-----+ | A | A_to_B / | B | B_to_C / | C | |-----| dispatch B_to_C |-----| dispatch C_to_A |-----| O---->| +------------------->| +------------------->| | | | | | | | +-----+ +-----+ +-----+ ^ C_to_A / | | dispatch A_to_B | +-----------------------------------------------------+
the following machine would immediately get into infinite loop by dispatching events as entry actions:
+-------------------+ +-------------------+ +-----+ | A | | B | | C | |-------------------| A_to_B |-------------------| B_to_C |-----| O---->| on entry: +---------->| on entry: +---------->| | | dispatch A_to_B | | dispatch B_to_C | | | | | | dispatch C_to_A | | | +-------------------+ +-------------------+ +-----+ ^ | | C_to_A | +---------------------------------------------------------------+