Documentation

Process for Entering, Executing, and Exiting States

Steps for Entering a State

A state becomes active in one of these ways:

  • An incoming transition crosses state boundaries.

  • An incoming transition ends at the state boundary.

  • It is the parallel state child of an active state.

A state performs its entry action (if specified) when it becomes active. The state becomes active before its entry action executes and completes.

The execution steps for entering a state are as follows:

  1. If the parent of the state is not active, perform steps 1 through 4 for the parent first.

  2. If the state is a parallel state, check if a sibling parallel state previous in entry order is active. If so, start at step 1 for this parallel state.

    Parallel (AND) states are ordered for entry based on whether you use explicit ordering (default) or implicit ordering. For details, see Explicit Ordering of Parallel States and Implicit Ordering of Parallel States.

  3. Mark the state active.

  4. Perform any entry actions.

  5. Enter children, if needed:

    1. If the state contains a history junction and there is an active child of this state at some point after the most recent chart initialization, perform the entry actions for that child. Otherwise, execute the default flow paths for the state.

    2. If this state has children that are parallel states (parallel decomposition), perform entry steps 1 through 5 for each state according to its entry order.

    3. If this state has only one child substate, the substate becomes active when the parent becomes active, regardless of whether a default transition is present. Entering the parent state automatically makes the substate active. The presence of any inner transition has no effect on determining the active substate.

  6. If the state is a parallel state, perform all entry steps for the sibling state next in entry order.

  7. If the transition path parent is not the same as the parent of the current state, perform entry steps 6 and 7 for the immediate parent of this state.

  8. The chart goes to sleep.

Steps for Executing an Active State

When states become active, they perform the following execution steps:

  1. Execute the set of outer flow charts (see Order of Execution for a Set of Flow Charts).

    If this action causes a state transition, execution stops.

      Note:   This step never occurs for parallel states.

  2. Perform during actions and valid on event name actions.

      Note:   Stateflow® charts process these actions based on their order of appearance in state labels.

  3. Execute the set of inner flow charts.

    If this action does not cause a state transition, the active children execute, starting at step 1. Parallel states execute in the same order that they become active.

Steps for Exiting an Active State

A state becomes inactive in one of these ways:

  • An outgoing transition originates at the state boundary.

  • An outgoing transition crosses the state boundary.

  • It is a parallel state child of an activated state.

A state performs its exit actions before becoming inactive.

The execution steps for exiting a state are as follows:

  1. Sibling parallel states exit starting with the last-entered and progress in reverse order to the first-entered. See step 2 of Steps for Entering a State.

  2. If a state has active children, performs the exit actions of the child states in the reverse order from when they became active.

  3. Perform any exit actions.

  4. Mark the state as inactive.

State Execution Example

The following example shows how active and inactive states respond to events.

Inactive Chart Event Reaction

Inactive charts respond to events as follows:

  1. An event occurs and the chart wakes up.

  2. The chart checks to see if there is a valid transition as a result of the event.

    A valid default transition to state A exists.

  3. State A becomes active.

  4. State A entry actions (entA()) execute and complete.

  5. The chart goes back to sleep.

Sleeping Chart Event Reaction

Sleeping charts respond to events as follows:

  1. Event E_one occurs and the chart wakes up.

    State A is active from the preceding steps 1 through 5.

  2. The chart root checks to see if there is a valid transition as a result of E_one. A valid transition from state A to state B exists.

  3. State A exit actions (exitA()) execute and complete.

  4. State A becomes inactive.

  5. State B becomes active.

  6. State B entry actions (entB()) execute and complete.

    The chart goes back to sleep.

Was this topic helpful?