LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array of cluster does not initialize!

Hello,

I agree with Ben – it sounds like a race-condition occurs due to multiple writers to the very same global.

If I would summarize global variables it would be like this:

Global variable is a location in memory that can be accessed by multiple VIs.

Pros: easy to use, works fine for data smaller than 32-bits

Negative: not suitable for large amounts of data, lossy since it can be overwritten before the data is read. A VI with a lower priority might not have enough processor time to read the data before other VIs overwrite the data. It might affect determinism since it is a shared resource (mutex).

Definitely go for Functional Globals considering you are using LV RT 7.x, if you not explicitly set it to be reentrant only one copy exists in memory.

Summary of functional globals:

SubVI store data in shift register. Minimize jitter by setting it to a subrouting priority level.

If it is skipped it will return the default value for the data type and not the default indicator values.

An easy way to see if it was executed or not is to use a Boolean Output that is set to True.

If is executes it will return a True if not a False (default value for Booleans)

Functional global variables can be a lossy form of communication; if a VI overwrites the shift register data before another VI reads the data

Regards,
Jimmie Adolph
Systems Engineering Manager, National Instruments Northern European Region

Message 11 of 17
(1,475 Views)

Jimmie wrote "Functional global variables can be a lossy form of communication; if a VI overwrites the shift register data before another VI reads the data"

This is true for the simplest form of AE's.

I have written AE that survive a power failure for the machine they are running on or comm failures (when the AE's are being used share data between distributed nodes) such that they pick-up right were they left off and only loose data when one of the machines is down for an extended period of time ( i.e. days ).

No other form of data sharing can make those claims. Smiley Wink

Gotta love those AE's!

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 12 of 17
(1,471 Views)
Ben likes AE, right? Smiley Happy

graziano
0 Kudos
Message 13 of 17
(1,457 Views)
"
 
Ben likes AE, right?

graziano
"
 
You've got that right!
 
And the reason is, Action Engines behaviour and capabilities are limited only by our ability to code. All other mechanisms have limits or short-comings that are beyond our control.
 
Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 14 of 17
(1,448 Views)
Okay,
   trying to investigate for Race Conditions, I've build a really silly, but impressive, test.  The two vectors should have the same values at the end of execution, while each time it's different, for the second array.

   Okay, in the example I use the Global variable in quite a stupid way, I know... Smiley Happy

graziano
0 Kudos
Message 15 of 17
(1,419 Views)
Hi Graziano,

your test isn't "impressive", it's a superb example for a race condition Smiley Wink.

When using the global all read/write accesses are completely unsyncronized! That's why you get different results in each run: you can't say what the second loop is reading while the first loop is writing to the global!.

Btw: Why do you use for loops in your example? You don't need them (increment/decrement also work on arrays)...


Message Edited by GerdW on 01-24-2008 05:27 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 16 of 17
(1,411 Views)
Hi GerdW,
   I know that, my example was a little "exagerate", just to show how global variables ( + intended bad programming technique! ) can have unpredictable results.  This was my first explicit race condition, and it impresses me in non-determinism! I knew the theory, but seeing it in action is different!

   Anyway, some debugging revealed that (appearently) I didn't fall in a race condition, since I provided some basic mechamism for mutex-ing accesses.

   Anyway (2), AE would do me with my purpose: my global acts as a circular buffer, and it was used more and more extensively in the application, so I started coding (some years ago!), and now I find that a strong refactoring would be good!

graziano
0 Kudos
Message 17 of 17
(1,406 Views)