Skip to main content

SA0006: Write access from several tasks

Detects variables which are written to by more than one task.

Justification: A variable which is written in multiple tasks may change its value unexpectedly. This can lead to confusing situations. String variables (and on some 32-bit systems also 64-bit integer variables) can even reach an inconsistent state if the variable is written to two tasks simultaneously.

Exception: In specific cases, it may be necessary for several tasks to write a variable. For example, use semaphores to make sure that access does not lead to an inconsistent state.

Importance: High

PLCopen rule: CP10

Example 18. Example
VAR_GLOBAL
    g_iTemp1: INT;
END_VAR
PROGRAM PLC_PRG    // Controlled by MainTask
g_iTemp1 := g_iTemp1 + INT#2;
PROGRAM PLC_PRG_1  //Controlled by SubTask
g_iTemp1 := g_iTemp1 - INT#3;

Output in the Messages view:

  • sa_icon_message.png SA0006: Concurrent write access to 'g_iTemp1' in Tasks MainTask, SubTask