Early Return Logic for Event Broadcasts

Guidelines for Proper Chart Behavior

These guidelines ensure proper chart behavior in event-driven systems:

  • When a state is active, its parent should also be active.

  • A state (or chart) with exclusive (OR) decomposition must never have more than one active child.

  • If a parallel state is active, siblings with higher priority must also be active.

How Early Return Logic Works

Stateflow® charts run on a single thread. Therefore, charts must interrupt current activity to process events. Activity based on an event broadcast from a state or transition action can conflict with the current activity. Charts resolve these conflicts by using early return logic for event broadcasts as follows:

Action Type

Early Return Logic

Entry

If the state is no longer active at the end of the event broadcast, the chart does not perform remaining steps for entering a state.

Exit

If the state is no longer active at the end of the event broadcast, the chart does not perform remaining exit actions or transitions from state to state.

During

If the state is no longer active at the end of the event broadcast, the chart does not perform remaining steps for executing an active state.

Condition

If the origin state of the inner or outer flow chart — or parent state of the default flow chart — are no longer active at the end of the event broadcast, the chart does not perform remaining steps for executing the flow chart.

Transition

If the parent of the transition path is not active — or if that parent has an active child — the chart does not perform remaining transition actions and state entry actions.

Example of Early Return Logic

In this example, assume that state A is initially active. Event E occurs, causing the following behavior:

  1. The chart 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 to state B exists.

  3. The condition action of the valid transition executes and broadcasts event F.

    Event F interrupts the transition from A to B.

  4. The chart root checks to see if there is a valid transition out of the active state A as a result of event F.

  5. A valid transition to state C exists.

  6. State A executes its exit action.

  7. State A becomes inactive.

  8. State C becomes active.

  9. State C executes and completes its entry action.

State C is now the only active child of its chart. The Stateflow chart 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 the chart allowed the transition, state B would become the second active child of the chart. This behavior violates the guideline that a state (or chart) with exclusive (OR) decomposition can never have more than one active child. Therefore, the chart uses early return logic and halts the transition from state A to state B.

    Tip   Avoid using undirected local event broadcasts, which can cause unwanted recursive behavior in your chart. Use the send operator for directed local event broadcasts. For more information, see Broadcast Events to Synchronize States.

    You can set the diagnostic level for detecting undirected local event broadcasts. In the Model Configuration Parameters dialog box, go to the Diagnostics > Stateflow pane and set the Undirected event broadcasts diagnostic to none, warning, or error. The default setting is warning.

Was this topic helpful?