12-17-2009 10:16 AM
I have two layers to many of my applications. A GUI layer, where I can customize the visualizations for the user to suit their need or preferences and an underlying control loop/DAQ loop/whatever that supports it. While critical data paths are handled through events, queues, or direct data paths, information to the GUI is displayed more indirectly through Global Variables or setting/reading the property value on the GUI's control or indicator reference. I pass the reference through a global which contains clusters of the references. So program controls like stop, start, logging, etc are under the Program Control References global variable. Alternatively, I use a Global Variable to pass the data back and forth without the reference. This is excellent for passing data to a logging system, since I don't generally mind when I grab my data, so long as it is once a second.
My question is, which do you, fellow LV developers, believe is a better choice? Changing via the property tends to be slower than directly changing a global variable, but Global Variables have that race condition problem. I have heard (and maybe witnessed, not sure) data collissions where a read and a write occur at the same instant. Is this a legitimate concern? From what I understand, this is less of a problem from Property value changes, but I am not sure if that is true.
What would be a safer method? Obviously direct data paths would be safer for the data, but for a control loop, it creates a timing dependancy which I won't allow.
12-17-2009 10:20 AM
You get exactly the same race conditions using property nodes compare to globals, so I don't know why you think there is a difference. I would stay with the globals.
If you ever get a chance to re-architect your application, have a look at state machines. You don't really describe your application well enough for us to decide if there are better ways for all that. 😉
12-17-2009 10:29 AM
I was afraid of that. How would a state machine help? I understand I would have obvious modes for the application to be in. Are you suggesting, one state would be a control state and the other a update GUI state? So in the update GUI state, I can safely access front panel data while the control state, the control loop can operate? Perhaps I misunderstand.
And can data collissions occur where race conditions are possible?
12-17-2009 11:09 AM
There is a transfer buffer between the data on the BD and the data on the FP, so no data collision might happen. But of course race conditions such as in a concurrent read-modify-write will give you problems.
As the GUI normally already has an event structure, you might consider using user events to send update information to the GUI. See my Event nugget for more ideas how to solve it.
Maybe you also can just downscale your code to the scenarios/use cases you want to solve and post this for us to have a look at.
Felix