5-37
5 Designing Tasks
NJ-series CPU Unit Software User’s Manual (W501)
5-2 Task System
5
5-2-13 Ensuring Concurrency of Variable Values between Tasks
Because of this, do not use exclusive control of variables in tasks to pass the values of global
variable if you are using the ActEventTask instruction to execute event tasks. To ensure the
concurrency of global variables when using the ActEventTask instruction, you should use the
Task_IsActive (Determine Task Status) instruction. The Task_IsActive instruction determines
whether the specified task is in execution or waiting to be executed. Use this instruction to pre-
vent other tasks from accessing variables that the event task writes to while it is in execution.
Refer to the NJ-series Instructions Reference Manual (Cat. No. W502) for details on the
Task_IsActive instruction.
Restrictions
• Only one refreshing task can be set for each global variable. If it is necessary to write a global
variable from more than one task, use the task exclusive control instructions described below to
ensure concurrency.
• If you specify a refreshing task for a structure or union variable, you must specify only one refresh-
ing task for the entire structure or union variable. You cannot specify a different refreshing task for
different structure or union members.
• If you specify a refreshing task for an array variable, you must specify only one refreshing task for
the entire array variable. You cannot specify a different refreshing task for different array elements.
Do not write the value of a variable for which concurrency is required from any task that is not the
refreshing task, e.g., do not write the value from the accessing task. If you read or write the value
of a variable for which a refreshing task is set from any task that is not a refreshing or accessing
task, the concurrency of the global variable may be lost. If you write such a program, a warning is
given when the program is checked.
You can use a data trace to sample an external variable for a global variable for which settings for
exclusive control of variables in tasks are used. This allows you to sample the values of the
global variable in the refreshing and accessing tasks in a data trace. Refer to 8-5-4 Data Tracing
for information on data tracing.
Sysmac Studio Setting Procedure
Set the global variables for which to specify refreshing tasks, and set the accessing tasks in the Set-
tings for Exclusive Control of Variables in Tasks on the Task Settings Tab Page on the Sysmac Stu-
dio.
For details, refer to Settings for Exclusive Control of Variables in Tasks on page 4-9.