LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array of cluster does not initialize!

Hi all!
   I have an application for compact FieldPoint, and I'm using LV 7.1 + RT.

   I have a global variable, containing quite a complex data structure.  It is an array of fixed sze (50 elem), each element is a cluster.  The cluster contain some U8 and an array.

  At the beginning, this structure is not initialized (all grayed out, to keep it easy).  I first initialize it to 50 elements, set to zero, with Initialize array function.

   The strange thing, is that sometimes, the array keeps un-initialized!  I've check software around this, I initialize this array at each start, but some times it initializes (all elements to zero), sometimes not.

   I've also tried with build array function, and store it in the global variable containing it, but I got the same behavior.

   Am I missing something? Of course, I can work it out setting default value to 50 initialized elements, but... just want to understand!

   Thanks everybody....

graziano

Voilà :

 



Message Edited by Graziano on 01-21-2008 09:58 AM

Message Edited by Graziano on 01-21-2008 09:59 AM
0 Kudos
Message 1 of 17
(3,837 Views)

If that is a normal Global, I would first look for a race condition caused by two writters of the global.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 17
(3,828 Views)
Yes but.... I initialize the global in a configuration VI, before doing everything else, you can't have race condition there, i supose....

   Do you mean that 2 contemporary writes can reset global to "not initialized" state?

graziano
0 Kudos
Message 3 of 17
(3,826 Views)

In a general sense yes.

But if that is reaally the issue you are reporting, well it depends on how your code is written. I posted an example in my Action Engine Nugget that showed how race conditions can occur with Globals. The simlest answer is to make sure you only have a single writer of your global.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 17
(3,818 Views)
Hi again,
   I know race condition can set variables to an un-defined value, depending on code executing sequence, but.... really, I find it hard that a race condition can reset to uninitialized state, sorry if I keep with my doubt.....

   Unfortunately, I'm working with LV 7.1 and I can't use shared variables, that would do me, while I found Labview's semaphore a little odd, sometimes I implemented some home-made mutex to solve it, maybe I'll turn to that...

   Thanks for helping me, I've still a lot to learn! Smiley Happy

graziano
0 Kudos
Message 5 of 17
(3,814 Views)

Concider the following

A.VI reads from global, mods data and writes back to global

B.VI does the same.

If execution breaks down in multiple threads as

A.Vi reads

B.VI reads

A mods

B mods

A write back to global

B writes back to global

then the changes made by A are over-written by B.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 17
(3,794 Views)
Hi Ben,
   I know this, is quite a common behavior when using global, but as I said, I found it strange that race condition can reset global to un-initialized state. More: I've checked the code, and it seems to me that in the section giving problem it is impossible to have simultaneous reads and/or writes....

   I'll keep debugging, thanks again!

graziano
0 Kudos
Message 7 of 17
(3,765 Views)

I Graziano,

I don't know how much can it cost to you, but instead of global variables I strongly suggest functional global variable.
This way it's easier to deal with potential race condition.

You can use the following link to have a tip about functional global.
Basically is a sort of state machine that execute only one case for each call.

Improving Determinism with Functional Globals, LabVIEW 2-Style Globals, in LabVIEW Real-Time

Have a Good Day

Best regards

FiloP
It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong.
Richard P. Feynman
Message 8 of 17
(3,746 Views)

Yes Functional Global or Action Engine will prevent race conditions for shared data structures.

I wrote about AE's in my Action Engine Nugget where I also included a demo of how race conditions can occur using globals.

And while I am plugging Nuggets, in this Nugget by tst, we talked globals to death and I am still convinced "Globals are Evil" (Copyright tst).   Smiley Wink

Ben



Message Edited by Ben on 01-22-2008 08:57 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 17
(3,742 Views)
Hi all!
   I know functional global, but when I implemented this program I didn't so it would take me some refactoring.... I'll see what I can do!

graziano

0 Kudos
Message 10 of 17
(3,731 Views)