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:
- State exit actions starting with the old simple state up to the outermost exited composite state.
- Transition action.
- State entry actions starting with the outermost entered composite state down to the new simple or pseudo state.
- 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.
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:
- N state exit action
- M state exit action
- T1 transition 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:
- T2 transition action
- I1 initial state pointer action (exit and entry actions of the state L are not executed since that state is not exited)
- M state entry action
- I2 initial state pointer action
N state entry action
In case the selected transition is T3, the following actions are executed:
- L state exit action
- K state exit action (actions of the state V are not executed)
- T3 transition action
- S state entry action
- P state entry action
- I3 initial state pointer action
- O state entry action
- O state exit action
- P state exit action
- T4 transition action
- Q state entry action
- I4 initial state pointer action
- R state entry action
How can we improve this article?