DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B3019: variable shared between tasks outside a protected object

Catalog status: active. Default severity: error. Stable name: data-race. Family: Flow and effects.

Tasks run at the same time (see the Language Reference). A variable that two of them use, one of them writing it, would be read half-written or written twice at once: a data race. Verada finds what each task reads and writes, through every call (the main subprogram counts as a task), and requires such a variable to be a component of a protected object, whose operations hold its lock.

Example (Vada)

package Counters is
   Total : Natural := 0;
   task Up;
   task Again;     --  both bodies do `Total := Total + 1;`
end Counters;

Example (Varc)

package Counters {
    pub var Total: Natural = 0;
    pub task Up;
    pub task Again;     // both bodies do `Total = Total + 1;`
}

What to do

Make the variable a component of a protected object and use it through that object's procedures and functions, or give each task its own variable.

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See flow and effects, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.