LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2 parallel while loops with functional global to share data

Solved!
Go to solution

Hi,

 

I am having a problem with sharing data with functional globals between two parallel while loops:

 

  1.  One of the loop (bottom) generates random number periodically and write the sample to a functional global.
  2.  Another loop (upper) has a event structure and when it times out, it would read the functional global and plot the data point to a chart.

The problem is sometimes the functional global seems to get "locked" and the output becomes constant zero. It also appears that every time I first open the VI, it works just fine. But from the second time execution, it begins to have the problem.

 

Picture1.jpgPicture2.jpgPicture3.jpg

0 Kudos
Message 1 of 5
(3,070 Views)
Solution
Accepted by topic author Bo2008

You need to intialize your FGV Stop VI BEFORE your lower loop begins.  Although you are using a functional global variable, you still have a race condition.  The FGV gets read in the lower loop before it has a chance to be intialized with a false in the upper loop.  Functional global variables remember their data between runs of the VI.  So it is still set to stop from the last time you ran the VI.  The reason it works when your VI first opens is because the VI has not been in memory, so when it loads, it loads with the default value of False in the shift register.

0 Kudos
Message 2 of 5
(3,067 Views)

Why not use user events to update the UI? It is a better approach than the FG and will avoid race conditions.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 5
(3,046 Views)

Thanks for the idea. Where can I find an example related to this problem? I found one here:

https://decibel.ni.com/content/docs/DOC-21277

Is it relavant?

0 Kudos
Message 4 of 5
(3,036 Views)

Yes, that is one place. You can also look at the examples that ship with LabVIEW.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 5
(3,029 Views)