| Stateflow® | ![]() |
A Stateflow chart uses early return logic to resolve conflicts with event broadcasts from state or transition actions.
The following are primary axioms of proper chart behavior:
Whenever 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.
Stateflow charts run on a single thread. Therefore, charts must interrupt current activity to process events. In some cases, activity resulting from an event broadcast conflicts with the current activity. Charts resolve these conflicts by using early return logic, as in the following example:

In this example, assume that state A is initially active. Event E occurs causing the following behavior:
The Stateflow chart root checks to see if there is a valid transition out of the active state A as a result of event E.
The condition action of the valid transition executes and broadcasts event F.
Event F interrupts the transition from A to B.
The chart root checks to see if there is a valid transition out of the active state A as a result of event F.
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 second axiom that a state (or chart) with exclusive (OR) decomposition can never have more than one active child. Consequently, the chart uses early return logic and halts the transition from state A to state B.
To maintain primary axiomatic behavior, a Stateflow chart uses 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, 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 graph — or parent state of the default flow graph — are no longer active at the end of the event broadcast, the chart does not perform remaining steps for executing the flow graph. |
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. |
![]() | Execution Order for Parallel States | Semantic Examples | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |