<img height="1" width="1" src="https://www.facebook.com/tr?id=1101141206686180&amp;ev=PageView &amp;noscript=1">


How to Share Data and Mutexes LabVIEW 1

 In LabVIEW, there’s a ton of stuff under the hood that can affect how you code runs and ultimately affect the functionality of your code.  Have you ever debugged some code, turned on highlight execution and found that other pieces of code were also running slowly? Or have you found that sometimes a routine in your code runs slower when another [unrelated] process is running?

That could be because of blocking which is what mutexes do under certain circumstances. Mutex is short for a Mutual Exclusion object, its used for arbitration. It can be compared to a talking stick; often a mutex is used with shared resources to control who can access the shared data.  In LabVIEW, mutexes are often implied.  For example, a non re-entrant VI uses an implied mutex: only one instance of this kind of VI can execute at a time, thus when two instances attempt to execute simultaneously, only one can run and the other must wait until the other finishes: one instance blocks and the other instance has to wait.

Blocking is sometimes exactly what you want: a functional global encapsulates operations while modifying shared data which could cause race conditions if the functional global didn’t block.  But there are also sometimes where blocking can hurt efficiency and your code will run slower when it doesn’t have to.  Generally, the amount of time blocking occurs is negligible, except for situations where the code that’s blocking takes a significant amount of time to run.

Alternatively, a re-entrant VI will not block while other instances of it are running. Two instances of a re-entrant VI can execute simultaneously but, if there is a VI contained within (however deep) that is non-re-entrant that attempts to run simultaneously, it will block.

Traditionally, functional globals are always non re-entrant. This ensures that every instance of the functional global points to the exact same memory space. When not using non re-entrant execution, there is no easy way to ensure what memory location each instance of the VI is associated with therefore it’s difficult to ensure that you modify common data.

We’ve included three examples providing situations where mutexes are implied, how it can effect execution time and how execution modes affect functional globals. Source code is available here: lv_mutex_shared_1.zip

Example 01: Shows the difference between non re-entrant execution and re-entrant execution and how it affects execution time.


Example 02: Shows an example of two re-entrant VIs running simultaneously with a non re-entrant VI that attempts to run simultaneously in each re-entrant instance.


Example 03: Shows how different kinds of execution  mode can affect functional globals and how it affects how each VI runs.


Some of this may push you to wonder how you can maintain speedy execution by reducing dependency on non re-entrant data sources using wires, but that also comes with its own problems.  We provide a solution to this issue in the next installment of this blog series!

Recent Posts:

Filtering Basics: Importance of Linear Phase
Publish Date 05 Apr 2017 Jason ThaiJason Thai

Linear phase and computation/memory complexity are important characteristics to [..]

Revisiting OAuth 2 in LabVIEW
Publish Date 05 Apr 2017 John AmstadtJohn Amstadt

Recap In my previous blog, we took a look at how to implement OAuth2 in LabVIEW. [..]

Engineering a Better 3D Print (Part 1)
Publish Date 05 Apr 2017 Michael MaloneyMichael Maloney

3D Printing and its widespread use has been a long time coming and seems to have [..]

NVCC – Intro to Utilizing GPU Power to Offload the CPU Part 3
Publish Date 05 Apr 2017 Jack BakerJack Baker

Assumptions: Machine has a Nvidia CUDA Core GPU (such as a GeForce) with installed [..]

How I Learn New Skills for Personal Growth
Publish Date 05 Apr 2017 Bryce UrestiBryce Uresti

Learning new skills can be quite the task especially when there's already so much [..]

Controlling the Supply Chain Dream
Publish Date 05 Apr 2017 Thomas MathewThomas Mathew

You are out with your friends, bird watching, and nothing could be more peaceful. [..]

Aligning Data in WAVE
Publish Date 05 Apr 2017 Rohama KhadijaRohama Khadija

When analyzing data from multiple sources, we often find that the time series data [..]