Font size

Execution order

It is important to know exactly what the order is of the execution of statechart elements' actions. For this reason we present the following algorithm.

When a transition is taken, transition and state actions are executed in the following order:

  1. State exit actions starting with the old simple state up to the outermost exited composite state.
  2. Transition action.
  3. State entry actions starting with the outermost entered composite state down to the new simple or pseudo state.
  4. If the control enters a pseudo state, its action code is executed, and then the control goes out of the pseudo state immediately, and this algorithm applies again from the beginning.

Actions associated with statechart elements (states and transitions) are executed atomically and in zero model time. Therefore they cannot contain synchronization and delay operations, or call functions directly or indirectly containing them.


Execution order illustration

Consider the example shown in. Suppose N is the current simple state and transition T1 has been selected to be taken. Then the actions are executed in the following order:

  1. N state exit action
  2. M state exit action
  3. T1 transition action
  4. Branch action

    Then the transition T2 or T3 is selected depending on guards of the transitions. In case the selected transition is T2, the following actions are executed:
  5. T2 transition action
  6. I1 initial state pointer action (exit and entry actions of the state L are not executed since that state is not exited)
  7. M state entry action
  8. I2 initial state pointer action
  9. N state entry action

    In case the selected transition is T3, the following actions are executed:
  10. L state exit action
  11. K state exit action (actions of the state V are not executed)
  12. T3 transition action
  13. S state entry action
  14. P state entry action
  15. I3 initial state pointer action
  16. O state entry action
  17. O state exit action
  18. P state exit action
  19. T4 transition action
  20. Q state entry action
  21. I4 initial state pointer action
  22. R state entry action
How can we improve this article?