LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how global variables are updated

Hello

I'm trying to make a VI with sub-VIs that exchange data with them.  The VI updates a global variable and then calls the subVI.  The subVI reads the data and works and it is supposed to work.
I have had problems with the variable update.  I have search in the forum and all the responses I have found suggest that it's better to use LV2 globals than the "traditional" globals.
Although I'm going to try this method, I'd like to know how works the system and how global variables are updated when there are loops, subVI calls... in the main VI.
Thank you in advance
Carlos Arcediano del Amo
0 Kudos
Message 1 of 8
(3,847 Views)
People tell you to stay away from globals because there are no dependencies as is normal with dataflow. If you have not used LV2 style globals (uninitialized shift registers) before, it is a very good idea to invest some time into this technique. It is probably best to find some tutorial/examples on this website.
0 Kudos
Message 2 of 8
(3,836 Views)
I was not very succesful finding a tutorial on how to create cool functionality with uninitialized shift registers, so I decided to make you a little example. I hope it illustrates something useful for you. The interesting part is the subvi. It uses an uninitialized shift register to store a variable. The subvi can be used to set the variable or to retrieve the variable. This example far from examplifies the possibilities of the LV2 global, but it does show one thing well: That there is no data dependencies (wires) between the two locations where the subvi is called. This means the data contained in the subvi can be managed and accessed from anywhere in your program, much like a global. This principle can be extended to make very sophisticated ways of data managment inside your program, as well as controlling the flow of the program (and much more).

The example requires LV7.1

Message Edited by aartjan on 09-20-2005 11:57 PM

0 Kudos
Message 3 of 8
(3,822 Views)
Thank you.  I'll try your VI
Carlos Arcediano del Amo
0 Kudos
Message 4 of 8
(3,806 Views)
Hi
 
I often use the normal global variables and never had problems using them. If I handle critical data, I use access vis which contain semaphores to avoid inconsistency.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 5 of 8
(3,801 Views)
Hello

My application doesn't have critical data.  The global variable contains configuration data that is only written once and read only once too.  I don't use threading, the execution is sequential.
Thanks
Carlos Arcediano del Amo
0 Kudos
Message 6 of 8
(3,795 Views)

Most people shy away from Globals because of the possibility of race conditions.  That is where a global might be read before it is written, or vice versa, in a manner that the wrong data gets read.  Since you write once and read once, you only have to ensure that the writting is done before the global is read, by using either data flow methods or sequence structure.  Once you are sure that you won't have a race condition, it is perfectly OK to use globals.  That is what they are there for.  I use globals as constants to hold GPIB addresses, calibration factors, and other things that are defined upon creation and never changed.  Can't have a race condition if the global is never written to.

See the attached example for how a race condition can occur.

 

Message Edited by tbob on 09-21-2005 10:56 AM

- tbob

Inventor of the WORM Global
Message 7 of 8
(3,779 Views)
Hello

I told before that I was modifiying a previous application.  Well, I have found what happened.  The indicators where inside a frame of a sequence, and this frame wasn't the first one.  Result:  The indicator wasn't updated until the execution arrived to that frame.  The globals worked as they was supposed to.

Thanks to everybody
Carlos Arcediano del Amo
0 Kudos
Message 8 of 8
(3,746 Views)