LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Share cluster data between 2 timed loops

What is the best and safest way of sharing cluster data between 2 timed loops running. I could use locals, but that is risky, would shared variables work better? All I need to do is modify a couple of datatypes in a cluster that both threads use.

 

Thanks...

0 Kudos
Message 1 of 23
(2,487 Views)

You could go the LVOOP route and create a singleton object. The object can be passed to parallel tasks an dsince it is singleton they will all share the same value. Ue of a DVR inside the object would allow you to have a single copy of the data. Your class would also give you the necessary accessors for reading/writing data.



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 2 of 23
(2,480 Views)

Maybe a functional global will do the job also.

0 Kudos
Message 3 of 23
(2,469 Views)

Would this be the proper way to handle the functional global. I need to modify a data cluster from within another timedloop, but don't want to create a race condition doing it. I could use queues I guess too. But if this is thread safe, I'd rather use this method.

 

Thanks...

0 Kudos
Message 4 of 23
(2,458 Views)

It depends on how you want use. If you use FGV you can read the same value many time but when it goes for the data logging this may not be desirable. You can use the queue so that whenever you update the data you will be able to read it and you have the buffer so chance of data loss is very less.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 5 of 23
(2,446 Views)

Here is a functional global example: https://decibel.ni.com/content/docs/DOC-2143

And another one: https://decibel.ni.com/content/docs/DOC-20897

 

Basically, the functional global is a simple VI which you can call in 2 or more parallel running loops and/or VI's. You can read, write, or somehow manipulate the data stored in a uninitialized shift register of the FGV while loop based on the 'Action' selection (case structure).

 

It is pretty simple to use and very easy to implement. You can use 'First call?' or maybe 'init' action in order to initialize the shift register.

0 Kudos
Message 6 of 23
(2,431 Views)

Thanks guys that is helpful. Is there an example that maybe shows how this might be used though with multiple loops accessing the same functional global data loop since the examples just shows how to set it up. I guess I'm still a bit uncertain how to incorporate this method into my main test application that has 4 task loops running together. Is the functional global data that all 4 tasks access in separate loop with the uninitialized shift register? If there is an example of this actually implemented that would be helpful. Thanks so much.

 

 

 

0 Kudos
Message 7 of 23
(2,418 Views)

Don't miss to read Ben's Action Engine Nugget that tells everything clearly

-----

The best solution is the one you find it by yourself
Message 8 of 23
(2,415 Views)

I'm not using Sub-Vi's though, all of my loops and action are within one VI, so is it implemented the same way?

0 Kudos
Message 9 of 23
(2,409 Views)

Be careful with functional globals.  And there is a holy war going on here regarding the use of locals. There is a plethora of options in your Synchronization palette. I would suggest getting very familiar with methods there. Plenty of examples.

PaulG.

LabVIEW versions 5.0 - 2020

“All programmers are optimists”
― Frederick P. Brooks Jr.
Message 10 of 23
(2,403 Views)