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:
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:
A
as a result of event E
.
B
is found.
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
.
A
as a result of event F
.
C
is found.
A
executes its exit
action.
A
is marked inactive.
C
is marked active.
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:
![]() | State Execution Example | Semantic Examples | ![]() |