Showing results for 
Search instead for 
Did you mean: 

Reading from a single process shared variable from multiple places?

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.

0 Kudos
Message 1 of 5

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.

"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 5

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

0 Kudos
Message 3 of 5

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.


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]

"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 5

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

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 5