11-30-2022 10:57 AM
I'm trying to figure out if it's okay to write to one single process shared variable, and then read from that variable in multiple other places. I am not, I repeat I am not, using the FIFO option. The only thing I care about is the instantaneous value at the time of reading. I just want to make sure I'm not having any blocking occurring.
Example of what I'm wondering is ok to do or not:
Or would I have to do something like this:
The second option would be pretty annoying since I may need to use the same value in many different places.
11-30-2022 11:04 AM
What is wrong with just using an Action Engine? Or a Named Notifier? Or even a Global?
If everything is running in the same context the SPSV is just begging for abuse.
11-30-2022 11:06 AM
Yeah as soon as I posted this, I realized there is an actual global variable type in LabVIEW. For some reason I'm stuck on thinking that the way to implement a global variable is with a shared variable
11-30-2022 11:21 AM
A LabVIEW Global can be very useful. But, it does break dataflow and can lead to race conditions if you are updating the value often and without protecting the data access
An Action Engine is usually safer.
Ben's famous Action Engine Nugget is always a good read. http://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/m-p/503801
And a Named Notifier can also be configured to ignore previous values or Wait until a new value is set.
Class data accessors are another means to protect data access.
We would need to know much more about exactly how you use the data to suggest which method may be best for your application.
[And then you'll get multiple opinions that differ]
11-30-2022 12:36 PM
A Single Process Shared Variable and a Global Variable are basically equivalent. I have not played around with SPSVs to see if there is any performance difference between the two. Not likely anything significant.
As far as your use, this looks like an acceptable use of them: Tag data (single value, not a messaging scheme), 1 writer, many readers.
To add to what Jeff said, I will give you this link: A Look At Race Conditions