Stateflow    

Early Return Logic for Event Broadcasts

Stateflow employs early return logic in order to satisfy conflicts with proper diagram behavior that result from event broadcasts in state or transition actions.

The following statements are primary axioms of proper Stateflow behavior:

  1. Whenever a state is active, its parent should also be active.
  2. A state (or chart) with exclusive (OR) decomposition must never have more than one active child.
  3. If a parallel state is active, siblings with higher priority (higher graphical position in the Stateflow diagram) must also be active.

Because Stateflow runs on a single thread, when it receives an event it must interrupt its current activity to process all activity resulting from the broadcast event before returning to its original activity. However, activity resulting from an event broadcast can conflict with the current activity, giving rise to the event broadcast. This conflict is resolved through early return logic.

The need for early return logic is best illustrated with an example like the following:

In this example, assume that state A is initially active. An event, E, occurs and the following behavior is expected:

  1. The Stateflow diagram root checks to see if there is a valid transition out of the active state A as a result of event E.
  2. A valid transition terminating in state B is found.
  3. The condition action of the valid transition executes and broadcasts event F.
  1. Stateflow must now interrupt the anticipated transition from A to B and take care of any behavior resulting from the broadcast of the event F before continuing with the transition from A to B.

  1. The Stateflow diagram root checks to see if there is a valid transition out of the active state A as a result of event F.
  2. A valid transition terminating in state C is found.
  3. State A executes its exit action.
  4. State A is marked inactive.
  5. State C is marked active.
  6. State C executes and completes its entry action.

State C is now the only active child of its chart. Stateflow cannot return to the transition from state A to state B and continue after the condition action that broadcast event F (step 3). First, its source, state A, is no longer active. Second, if Stateflow were to allow the transition, state B would become the second active child of the chart. This violates the second Stateflow axiom that a state (or chart) with exclusive (OR) decomposition can never have more than one active child. Consequently, early return logic is employed, and the transition from state A to state B is halted.

In order to maintain primary axiomatic behavior in Stateflow diagrams, Stateflow employs early return logic for event broadcasts in each of its action types as follows:

Action Type
Early Return Logic
Entry
If the state is no longer active at the end of the event broadcast, any remaining steps for entering a state are not performed.
Exit
If the state is no longer active at the end of the event broadcast, any remaining exit actions or steps in transitioning from state to state are not performed.
During

If the state is no longer active at the end of the event broadcast, any remaining steps in the execution of active state are not performed.

Condition
If the origin state of the inner or outer flow graph or parent state of the default flow graph is no longer active at the end of the event broadcast, the remaining steps in the execution of the set of flow graphs are not performed.
Transition
If the parent of the transition path is not active or if that parent has an active child, the remaining transition actions and state entry are not performed.


  State Execution Example Semantic Examples