Multi-task data access synchronization in the PLC

When the same data is accessed by multiple tasks, the tasks may access the same data simultaneously, depending on the task/real-time configuration. If the data is written by at least one of the tasks, the data may have an inconsistent state during or after a change. To prevent this, all concurrent accesses must be synchronized so that only one task at a time can access the shared data.

These concurrent accesses from several tasks that require synchronization include the following cases, for example:

To put it briefly: If the same data is accessed by several tasks and the data is written for at least one of these accesses, all read and write accesses must be synchronized. This applies irrespective of whether the tasks run on one or more CPU cores.


Inconsistencies and other risks due to unsecured data access

If concurrent accesses are not synchronized, there is a risk of inconsistent or invalid data records. Depending on how the data is used in the further course of the program, this can result in incorrect program behavior, undesired axis movement or even sudden program standstill. Depending on the controlled system, damage to equipment and workpieces may occur, or people's health and lives may be endangered.

To get a feeling for the necessity of access synchronization, you will find function tests with corresponding explanations in the sample programs for the MUTEX procedures.

Synchronization options

The following options are available for synchronizing accesses:

Synchronization also in the case of atomic access

The necessity for synchronization normally also applies even if a single access to a variable (e.g. writing an integer) could be described as atomic, i.e. uninterruptible.

Because the property of the atomic access depends among other things on the processor architecture used, every access should be regarded as non-atomic for simplicity's sake and for safety.

It should also be noted that even supposedly safe accesses almost always turn out to be unsafe when considered more closely. This is explained below with the help of two example scenarios:

Additional Notes