Concurrency in no-code MachineLogic

Applications dealing with incoming asynchronous events (e.g. sensors or push buttons) imply concurrency: you want to be able to receive events at all times, while also moving your robots and actuators.

Multi-threading, active loops and interrupts are classic ways of handling concurrency in computer programs, but they can get messy quickly.

MachineLogic (VSE) builds on the js ecosystem, to provide a single-threaded solution to this problem. The magic resides in non-blocking actions. Whenever an action is performed by a device other than the CPU (e.g. a disk drive; or an actuator), the CPU itself immediately returns to its event-handling state, instead of waiting.

As a result, one can program as many event-triggered sequences as desired, or as many concurrent state machines, almost without thinking about it. A single MachineLogic program can handle multiple conveyors and actuators. No need to worry about data corruption caused by concurrent access to shared data structures, deadlocks caused by tricky concurrency-control patterns, or obscure failures caused by subtle timing issues.

One thing to keep in mind is that long active CPU loops will prevent going back to the event-handling state. Fortunately, long active loops are not too common, and can be avoided easily (e.g. by inserting time outs).

3 Likes

This is a very informative kind of post - some nice technical information, and a really nice upside to MachineLogic.

2 Likes