Order Data Store Access

About Data Store Access Order

To obtain correct results from data stores, you must control the order of execution of the data store's reads and writes. If a data store's read occurs before its write, latency is introduced into the algorithm: the read obtains the value that was computed and stored in the previous time step, rather than the value computed and stored in the current time step.

Such latency may cause the system to behave other than as designed, and in some cases may destabilize the system. Even if these problems do not occur, an uncontrolled access order could change from one release of Simulink® to the next.

This section describes several strategies for explicitly controlling the order of execution of a data store's reads and writes. See Data Store Diagnostics for techniques you can use to detect and correct potential data store errors without running simulations.

Ordering Access Using Function Call Subsystems

You can use function call subsystems to control the execution order of model components that access data stores. The next figure shows this technique:

The subsystem Before contains the Data Store Write, and the Stateflow® chart calls that subsystem before it calls the subsystem After, which contains the Data Store Read.

Ordering Access Using Block Priorities

You can embed data store reads and writes inside atomic subsystems or Model blocks whose priorities specify their relative execution order.

The Model block beforeDSM has a lower priority then afterDSM, so it is guaranteed to execute first. Since beforeDSM is atomic, all of its operations, including the Data Store Write, will execute prior to afterDSM and all of its operations, including the Data Store Read.

Was this topic helpful?