From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-19-2005 11:31 AM
07-19-2005 12:23 PM - edited 07-19-2005 12:23 PM
Hi Tbob,
You wrote "scaring newcomers away from locals and globals like they are the plague".
Global variables are the plague in my book. I lived through that affliction once and I do not plan on doing it again.
There are very specific cases were it is possible to "get away" with using locals and globals. These cases all fall into the catagory of "single writer, multiple reads".
Local variables are usefull in updating the user interface but agian I have to be careful that I only have one writter at a time. As far as using them to pass info from loop to loop, your example shows the case were they can be used. If speed is not an issue and the data being passed is small, we not see much difference. When the data set get large the copies required for each instance of a local start gobbling up memory.
The next concern that keeps me away from globals is expansion and flexibity. The "local and global" route sets me up for disaster when the customers tells me "Could we have an erro in the DAQ read force the application to shutdown?". This is where the race condition comes in because it would be whichever writes last will win the update game (race condition).
By using LV2 globals or queues my code can be adapted without having to go back and eliminate all of the race conditions. LV2 globals will also quickly adapt into "action engines" that can handle more complicated situations like "Clear Run flag if set" which just can not be coded in a global or a local.
The attached image illustrates how I use a queue to pass commands from the UI loop (handles repsonding to user clicks) and the Execution loop that does the long drawn on tasks.
In the top loop I use a local only to signal the user that the button click was recognized. The bottom loop previews the queue to determine if a command was sent and only if the queue is not empty, will the queue be read.
So....
I discourage the use of globals in "ALL" cases. Locals are OK for updating user interface.
Message Edited by Ben on 07-19-2005 12:24 PM
07-19-2005 12:52 PM
1) what is an LV2 Global and where can I start learning the basics
2) i am assuming the shipping example of queue basics is where i should start learning about those?
07-19-2005 01:04 PM
07-19-2005 02:32 PM
07-19-2005 02:37 PM
guess i should have mentioned i have 7.0
sorry 😕
07-19-2005 02:53 PM
07-21-2005 05:07 AM
Thank you very much for all your responses. I learned lot and managed to solve my problem by using local variables. If I face anyproblems, I may consider queues.
Regards,
Ravi.