Example Code

Use FGVs as Action Engines to protect critical code sections

Code and Documents

Attachment

Overview

This project demonstrates how you can implement Functional Global Variables (FGVs) as action engines to ensure against code-breaking race conditions.

 

Description

Often when starting a new application, it is easy to forget to look forwards. I have often used local variables in small code without a second thought. This is all well and good if it is a small simple code that isn’t going anywhere, but what about when you want to expand it and increase functionality? You can start to come un-stuck with local variables as race conditions will creep up on you as your code expands. By using Action Engines from the start, you can save yourself time (and money) later by not having to re-work and debug a code to remove race conditions.

To ensure against code-breaking race conditions you can implement Functional Global Variables (FGVs) as action engines. (As a reminder: An FGV is a non-re-entrant sub VI which uses uninitialized shift registers to store data.) An FGV will store data for if it is kept in memory. An FGV that does anything more than reading and writing data is known as an Action Engine. Using the state machine within the FGV allows you to perform critical operations on data whilst protecting the code from race conditions.

 

Requirements

  • LabVIEW 2013 or compatible

 

Steps to Implement or Execute Code

  1. Download attached .zip file
  2. Extract folder to location
  3. Open Virtual Banker. lvproj in LabVIEW 2013
  4. Run Banker Action Engine.vi and Banker Local Variables.vi

 

Additional Information or References

 

 fgv.png

local.png

 **This document has been updated to meet the current required format for the NI Code Exchange. **

 

Tim, CLD, CTD
National Instruments (UK & Ireland)
________________________________________________
"No problem is insoluble in all conceivable circumstances"

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Ben
Knight of NI Knight of NI
Knight of NI
on

For more information on Action Engines see here where you will find a Nugget I wrote on the topic in 2007.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel