Lifetime of Stateflow Messages
This example shows two important concepts underlying the lifetime of Stateflow® messages.
When a Message Is Removed from the Input Queue
A message is removed from the input queue as soon as the chart evaluates a message transition trigger even if the transition itself is not taken. To clarify this, consider the interaction between the following two charts:
The chart "Sender1" sends a message with data 3 at time t = 0. When "Receiver1" evaluates the transition "M[M.data == 5]" at time t = 1, this message is immediately removed from the input queue even though the condition "M.data == 5" is false and the transition is not taken. This message is then destroyed at the end of time t = 1.
At time t = 3, "Sender1" sends another message with data 5. This time, when "Receiver1" evaluates the transition, the condition "M.data == 5" is satisfied and "Sender1" transitions from A to B.
If the first message sent by "Sender1" at t = 0 were to remain in the input queue of "Receiver1", then the transition from "A" to "B" could never be taken.
Evaluating Multiple Message Triggers in the Same Time Step
When a chart evaluates a message trigger for the first time in a time step, it checks whether a message is present in the queue and removes it from the queue. This message is then considered valid and used throughout that time step unlesss it is forwarded to another queue. If in the same time step, the chart evaluates another trigger with the same message, the existing valid message is used rather than removing another message. To clarify this, consider the interaction between the charts "Sender2" and "Receiver2".
"Sender2" sends two messages at time t = 0, the first with data 3 and the second with data 5.
At t = 1, when checking the outer transitions of "A", "Receiver2" removes the first message (with data 3) from the queue and transitions from "A" to "B". In the same time step, the default transition flow graph inside "B" evaluates another transition also triggered by "M". Since a message has already been removed from the queue in this time step, the chart uses that message instead of removing another message. Since the first message has data = 3, the condition "M.data == 3" is true and the chart transitions to "B.B1".