日本語 English

Mutual exclusion

What Is Mutual Exclusion?

Mutual exclusion is control that waits for the running process to finish before executing, so that processes that cannot run simultaneously do not overlap
For example, if [Process A] and [Process B] both write to a file on the memory card, and [Process B] needs to run while [Process A] is running, it waits for [Process A] to finish before running [Process B]

Overview

On the OMRON NX/NJ series, SD card access, database writes, socket communication, OPC UA communication and so on have limits on how many can be processed simultaneously. If the limit is expected to be exceeded, you need to reduce the number of processes or handle them exclusively
Here we introduce a mutual exclusion sample that can manage 64 processes.

How to use the sample program

Unions

The union is used in the program, so be sure to create it
Unions

Global variable

To manage 64 processes exclusively, create 64 request flags, execution flags and completion flags
Trigger: request flag = turn ON when you want to execute (the request is recognized on the rising edge)
Run: execution flag = turns ON when execution is allowed after mutual exclusion (use this flag to start processing)
Fin: completion flag = turn ON when processing completes (no other Run flag turns ON until this turns ON)
Global variable

Program

Copy the whole sample program SampleExlusiveControl and paste it into the project where you want to use it
It can be used as-is, with nothing in particular to change

Preparation

Assign each of the processes you want to manage exclusively a unique process number from 0 to 63
Assign higher-priority processes to larger process numbers

Mutual exclusion procedure

  1. Turn ON the Trigger of the process number you want to start
  2. The Run of the process number allowed to execute after mutual exclusion turns ON, so use this flag to execute the process
  3. When processing is finished, turn Fin ON

Execute the process while Run is ON
Turning Fin ON turns Run OFF
If Fin is turned ON after Trigger turns ON but before processing completes (whether Run is ON or OFF), it is canceled and the next waiting Run turns ON

When Run turns ON after mutual exclusion

Example of 4 exclusive processes
When Run turns ON after mutual exclusion

  1. Trigger[0] and [3] turn ON at the same time
  2. Trigger[3] has higher priority, so Run[3] turns ON
  3. When Run[3] completes and Fin[3] turns ON, the waiting Run[0] turns ON
  4. Trigger[2] turns ON while Run[0] is processing, but it waits because Run[0] is processing
  5. When Run[0] completes and Fin[0] turns ON, the waiting Run[2] turns ON

In this way, mutual exclusion ensures that only one Run flag turns ON at a time, in order

Download

Comments