2 Instruction Descriptions
2-876
NJ-series Instructions Reference Manual (W502)
Lock regions with different values for Index do not affect each other.
• The Lock and Unlock instructions are used when the same data is read/written from more than one
task. They are used to prevent other tasks from reading/writing the data while a certain task is read-
ing/writing the data.
• As long as the Index values are different, more than one pair of Lock and Unlock instructions can be
placed in the same POU. The instruction pairs can also be nested.
• Do not make lock regions any longer than necessary. If the lock region is too long, the task execution
period may be exceeded.
• Always use the Lock and Unlock instructions together as a set in the same section of the same POU.
• You can set a maximum of 16,777,215 lock regions at the same time.
Additional Information
Precautions for Correct Use
Task T1
Task T2
The priority of T1 is higher than the
priority of T2, so T2 is interrupted
and execution of T1 is started.
Execution priority
High
Low
Lock region
Normal execution
Lock(1)
Execution interrupted.
Unlock(1)
Lock(1) Unlock(1)
T2 executes a Lock instruction with the same Index
value as the Lock instruction in T1. Therefore,
execution of T1 is interrupted until the Unlock
instruction is executed in T2.
When the Unlock instruction is executed in T2,
execution of T1 is started again, and execution of T2
is interrupted.
Execution of T2 is started again
after T1 completes execution.