8 - 11 8 - 11
MELSEC-Q
8 MULTITASK PROCESSING
(3) Execution order of instructions when limiting access to the
resources
The following describes the execution order of instructions when limiting access
to the resources in the BASIC program.
ZRESERVE:
Requests mutual exclusive control of the resource.
ZRELEASE:
Finishes mutual exclusive control of the resource.
BASIC
program (A)
BASIC
program (B)
The privilege to use the resource
is transferred to program B, which
was kept waiting in the meantime.
Program B requested to use
the resource but is put into
the wait status because
program A is using the resource.
The use of the resource
is finished and
the resource is released.
The privilege to use
the resource is
transferred to program A.
Device to which
access is limited
(Resource number n)
ZRESERVE n
Request
Use
Finish
ZRESERVE n
ZRELEASE n
In use
ZRELEASE n
Request
Use
Finish
In use
As shown above, use the resource after executing the ZRESERVE instruction in order
to use the resource assigned to resource number n. Execute the ZRELEASE
instruction in order to finish using the resource.
Care must be taken when each of the programs executed simultaneously uses multiple
resources. If the order of the resource numbers specified by each ZRESERVE
instruction is not handled as arranged, both programs may keep each other from being
able to continue. (Deadlock prevention)
An example of a deadlock is shown next.