Tasklocal variables are cycle-consistent. In a task cycle, they are written only by a defined task, while all other tasks have read-only access. It is taken into account that tasks can be interrupted by other tasks or can run simultaneously. The cycle consistency also applies above all if the application is running on a system with a multicore processor.
Therefore, using task local global variable lists is one way to automatically achieve a synchronization (by the compiler) when multiple tasks are processing the same variables. This is not the case when using ordinary GVLs. Multiple tasks can write simultaneously to ordinary GVL variables during a cycle.
However, it is imperative to note: The synchronization of tasklocal variables requires a relatively large amount of time and memory and is not always the best solution for every application. For this reason, see below for more detailed technical information and "best practice" guidance to help you make the right decision.
In the CODESYS project, the
“Global Variable List (tasklocal)” object is available for defining tasklocal variables. Syntactically, it corresponds
to a normal GVL, but also contains the information of the task that has write access
to the variables. Then all variables in such a GVL are not changed by another task
during a cycle of a task.
The next section contains a simple example that demonstrates the principle and functionality of tasklocal variables. It includes a writing program and a reading program. The programs run in different tasks, but they access the same data that is stored in a tasklocal global variable list so that they are processed cycle-consistently.
-
Showing functionality in an example
-
Constraints in the declaration
-
Properties of tasklocal global variables and possible behavior
-
Best practice
-
Monitoring
-
Background: Technical implementation
-
Instructions for creating the sample application as described above