SA0006: Write access from several tasks

Function

Determines variables with write access from more than one task.

Reason

A variable that is written in several tasks may change its value unexpectedly under certain circumstances. This can lead to confusing situations. String variables and, on some 32-bit systems, 64-bit integer variables also may even assume an inconsistent state if the variable is written in two tasks at the same time.

Exception

In certain cases it may be necessary for several tasks to write a variable. Make sure, for example through the use of semaphores, that the access does not lead to an inconsistent state.

Importance

High

PLCopen rule

CP10

SA0006: Write access from several tasks 1:

See also rule SA0103: Concurrent access on not atomic data.

SA0006: Write access from several tasks 2:

Call corresponds to write access

Please note that calls are interpreted as write access. For example, calling a method for a function block instance is regarded as a write access to the function block instance. A more accurate analysis of accesses and calls is not possible, e.g. due to virtual calls (pointers, interface).

To deactivate rule SA0006 for a variable (e.g. for a function block instance), the following attribute can be inserted above the variable declaration: {attribute 'analysis' := '-6'}

Samples:

The two global variables nVar and bVar are written by two tasks.

Global variable list:

VAR_GLOBAL
    nVar  : INT;
    bVar  : BOOL;
END_VAR

Program MAIN_Fast, called from the task PlcTaskFast:

nVar := nVar + 1;                // => SA0006 
bVar := (nVar > 10);             // => SA0006

Program MAIN_Slow, called from the task PlcTaskSlow:

nVar := nVar + 2;                // => SA0006 
bVar := (nVar < -50);            // => SA0006