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.

Example

  

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:

  1. T2 transition action
  2. I1 initial state pointer action (exit and entry actions of the state L are not executed since that state is not exited)
  3. M state entry action
  4. I2 initial state pointer action
  5. N state entry action

In case the selected transition is T3, the following actions are executed:

  1. L state exit action
  2. K state exit action (actions of the state V are not executed)
  3. T3 transition action
  4. S state entry action
  5. P state entry action
  6. I3 initial state pointer action
  7. O state entry action
  8. O state exit action
  9. P state exit action
  10. T4 transition action
  11. Q state entry action
  12. I4 initial state pointer action
  13. R state entry action