09-25-2012 05:31 PM - edited 09-25-2012 05:38 PM
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...
09-25-2012 05:57 PM
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.
09-25-2012 09:00 PM
Maybe a functional global will do the job also.
09-25-2012 10:48 PM
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...
09-26-2012 12:27 AM
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.
09-26-2012 01:51 AM
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.
09-26-2012 06:20 AM - edited 09-26-2012 06:20 AM
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.
09-26-2012 06:26 AM
Don't miss to read Ben's Action Engine Nugget that tells everything clearly
09-26-2012 06:57 AM
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?
09-26-2012 07:30 AM
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.