5-9
5 Designing Tasks
NJ-series CPU Unit Software User’s Manual (W501)
5-2 Task System
5
5-2-3 Basic Operation of Tasks
Precautions for Correct UsePrecautions for Correct Use
If you have multiple tasks that read and write to the same variables, make sure to use exclusive
control of variables between the tasks. Otherwise, a task other than the one currently in execu-
tion may change the variable values. Refer to 5-2-13 Ensuring Concurrency of Variable Values
between Tasks for details.
A task with a higher execution priority is never interrupted to start execution of a task with a lower exe-
cution priority. However, if unused time occurs during a task with higher priority, that time may be used
to start execution of a task with lower priority. An example of this is the time spent waiting for a data
transfer to be completed in an I/O refresh process. As soon as processing resumes for the task with
higher priority, the task with lower priority will be interrupted. This processing order is illustrated in the
following figure.
Precautions for Correct UsePrecautions for Correct Use
Even if unused time occurs in the primary periodic task, the priority-16 periodic task is always
executed after the primary periodic task is completed. This restriction does not apply to the prior-
ity-17 or priority-18 periodic tasks. This restriction also does not apply to I/O refreshing in the pri-
ority-16 periodic task. I/O refreshing for the priority-16 periodic task may be executed during the
unused time of the primary periodic task.
Executing Other Tasks during the Unused Time of a Task
MC IO UPG MC IO UPG MC IO UPG MC IO UPG MC IO UPG
IO UPG
UPG
IO UPG
UPG
UPG
SS
System
services
Task period
Task period
Primary period
Priority-17
periodic task
Priority-16
periodic task
Primary
periodic task
Low
High
Execution priority
Primary periodPrimary periodPrimary periodPrimary period
Task execution
condition is
met.
Pausing Pausing
Pausing
Task
execution is
completed.
Task execution
condition is met.
Task execution
condition is
met.
Task
execution is
completed.
Task execution
is completed.
Task execution
condition is
met.
Task
execution is
completed.
Pausing Pausing
Pausing
Task execution
is completed.
Task execution
condition is
met.
Task
execution is
completed.
Task execution
condition is
met.
Task
execution is
completed.
Pausing
Task execution
condition is met.
Task execution
condition is met.
Primary period
Task period
The priority-17 periodic task is executed during
the unused time of the primary periodic task.
High
Low
MC
IO
UPG
UPG
UPG
Priority-17
periodic task
Primary
periodic task
Execution
priority
Task execution
condition is met.
Task execution
is completed.
Interrupted.
Unused
MC
IO
UPG