RE: local variable cross-talk?

Jeff
A global can be considered as a variable to the entire code, where lots of
different vi's can operate it. Locals only have any meaning within their
own vi, or instances of their own vi.
If anything writes to a particular global, whether in reenterent vi's or
not, it's available everywhere in the code.
What you were asking was about locals though. If a vi is non-renentrant
(i.e. as they come out of the box) then the values in the locals are vi
specific, no matter where the vi is, where it was last used, it retains the
data from it's last operation. If it is re-entrant, then the values in the
locals for each occurance of the vi are its own for EACH instance, i.e. just
like different locals in different vi's, it doesn't matter where else the vi
is used, the data held is that from the last operation of that specific
instance.
Simple way to demonstrate this. Make a vi that has one numeric control,
then code in +1 and get it to write to a local variable for that control.
Throw in an indicator to wire out the result of what is written to the local
for the control.
Then take this vi, put it in a for loop, then put another copy in the for
loop as well. Wire the indicators to the side of the for loop and create
indicator arrays for them. Get the loop to run 6 times say. Now try
running this with the vi in the for loop non-reentrant and then reenterrant.
One way the arrays will contain either all the odd no.s 1,3,5,7,9,11 and
then the other array 2,4,6,8,10,12 (don't know which array will be which,
depends which executes first in the for loop of this example). The other
way they will both be 1,2,3,4,5,6. In the first example, the same vi has
run 12 times, i.e. one copy of the vi which retains its info and is called
in many places and therefore only has one set of values, and the other with
two re-enterant copies where they have their information specific to that
instance of them i.e. effectively they are different vi's. Both ways are
useful, depends what you want.
If you're looking for a use for non-reenterant vi's then consider this:-
For instance. Supposing you get many things to try to write to a global
array of numbers, and you have two vi's one "A" writes to the first element
in the array and the other "B" writes to the second element. Because in LV
you have to read a global first and then write to it to perform a change,
these independant vi's "A" and "B" (be they re-enterant versions of the same
vi, or different vi's), can be performing the tasks simultaneously in the
code. I.e. "A" reads, "B" reads, "A" writes, and "B" writes over the top
with a modified version of what it read, and "A"'s changes are lost. This
is what's known as a "race condition" as "A" hadn't finished and "B" needed
to know what "A" was going to write before "B" performed "A" read. Try it,
hours of fun if you code this kind of thing in inadvertantly!
If the same vi is used, and is not re enterant, it can only run in one
instance at a time, hence two read / write operations cannot be performed
together, problem solved. Unless that gives you timing issues of course,
waiting for one to finish, to write the other......but that's another whole
can of worms.
cheers
Tim Price
This e-mail, its content and any files transmitted with it are intended
solely for the addressee(s) and are confidential and may be legally
privileged. Access by any other party is unauthorised without the express
prior written permission of the sender. If you have received this e-mail in
error you may not copy, disclose to any third party or use the contents,
attachments or information in any way.
-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Jeffrey W Percival
Sent: 29 November 2001 21:12
To: [email protected]
Subject: Re: local variable cross-talk?
Another useful reply! What a great news group this is.
One last thing I wanted to ask about, though, is global vs. local. I see
you talk about globals, but in fact the variables in my subVI's were locals.
I can easily understand the behavior I observed accompanying the use of
global variables, But I guess the use of the word "local" stumped me.
Should I interpret "local" in LabVIEW's sense to mean "local to all
instances of this VI"? And global to mean "visible to all instances of this
VI as well as other VI's"?
-Jeff
Tim Price wrote:
This facility is actually very useful, for instances where you want to
encapsulate some code so that it can only run in one place at a time,
i.e.
global arrays that are written to in more than one place. This method
can
eradicate race conditions completely for example when used like this.
There
are multiple other uses as well.
However, using a vi as a module of code, to run in more than one
instance at
a time simultaneously, re-entrant is the way to go. Just make sure you
debug it first!!!
Remember though, just because a vi may be re-eneterant, doesn't mean
that
everything inside is; sub-vi's, Globals etc. The classic one I've seen
is
where people think that a re-enterant vi is talking to it's own copy of
any
Globals used within it, i.e. counters etc., where in actual fact of
course,
they are all using the same Globals.
Worth playing with a few examples to get familiar with it.
Tim Price
Jeffrey W Percival, Senior Scientist and Associate Director
Space Astronomy Laboratory, University of Wisconsin - Madison
1150 University Ave, Madison, WI 53706 USA
608-262-8686 (fax 608-263-0361) [email protected]
http://www.sal.wisc.edu/~jwp

Tim Price wrote:
Tim, thanks very much. I'll try the experiment you suggest.
Thanks for taking the time.
-Jeff
Jeffrey W Percival, Senior Scientist and Associate Director
Space Astronomy Laboratory, University of Wisconsin - Madison
1150 University Ave, Madison, WI 53706 USA
608-262-8686 (fax 608-263-0361) [email protected] http://www.sal.wisc.edu/~jwp

Similar Messages

  • Local variable cross-talk?

    I have three VIs, call them A, B, and C. A uses C as a
    subVI, and B uses C as a subVI.
    Now, when A contains only C, I run A and everything is
    fine. C has a boolean control and indicator, very simple.
    When I place B in A's diagram, and leave it unwired, A no
    longer behaves correctly. A can no longer control C's
    boolean indicator. It's very strange.
    Now, the instance of C within B is wired such that C's
    boolean indicator is wired to False. In the instance of C
    within A, the boolean indicator is wired to a switch. It
    appears to me that just the presence of B within A causes
    A's boolean indicator to be controlled by B.
    Does this behavior ring a bell?
    Jeffrey W Percival, Senior Scientist and Associate Director
    Space Astronomy Labora
    tory, University of Wisconsin - Madison
    1150 University Ave, Madison, WI 53706 USA
    608-262-8686 (fax 608-263-0361) [email protected] http://www.sal.wisc.edu/~jwp

    With B in A and not wired to anything, it will run as a parallel thread to whatever is happening in A. What runs first is not predictable without analyzing the VI. What probably is happening is that A passes the switch value to C then the parallel thread B runs and passes its value to C. So the A VI is doing what it is supposed to, it's just that the B VI is also doing what it is supposed to. Put a delay in A before it passes its value to C (making B run first), then see if B appears to no longer have control.
    You might want to use the trace mode to see what it happening. Step through the program and watch what goes on.
    Rob

  • Local variables with cross dimensional operator

    Hi,
    I have a business rule, which has the following calculation :
    VAR TOTPROD;
    TOTPROD = "Prod1"+"Prod2"+"Prod3";
    "MBR1" = "MBR2"->"Jan"->TOTPROD/"MBR2"->"YearTotal"->"TotalProducts";
    The above statement does not run for obvious reasons that TOTPROD is not a member name.
    Is there a way to use a local variable in a cross dimensional operator statement?
    I want to use the local variable in order to avoid making an alternate hierarchy.
    I am using Essbase / HPB 11.1.2.2
    Please help.
    Thanks.

    Hi
    As you state, I dont think the approach that you have is going to work.
    What about either
    a. Creating a dummy product member in your outline and place your result on it (or use an existing 'dummy' product member)
    b. Re-write your code to handle what you wish to do....something like (assuming you are adding Prod1, 2 and 3):
    "MBR1" = ("MBR2"->"Jan"-> "Prod1"+"MBR2"->"Jan"-> "Prod2"+"MBR2"->"Jan"-> "Prod3")/"MBR2"->"YearTotal"->"TotalProducts";
    Not sure if I am missing anything here, but do either of these suggestions help?
    JB

  • Labview FPGA: Why not have local variable without indicator?

    In Labview FPGA, to transfer data among parallel loops, there are three ways or maybe more, local variable, global variable and block memory. The problem with local variable is that it needs an indicator along with, not like global variable. I was thinking why Labview doesn't make a kind of local variable not need indicator? I guess local variable itself doesn't cost resource much compared to global variable, however when it comes into indicator, it will cost more. Just an idea, though. I guess there is a reason NI doesn't do that. 

    As in Labview document, global variable can be used for transfer data among VIs, which local variable isn't capable of. 
    Global variable is not always a better solution. From my experience, it is still unclear among different compilations using local vs global in terms of resources. A thread here http://forums.ni.com/t5/LabVIEW/FPGA-global-variables-vs-front-panel-items/td-p/1407282 talks about that too.
    Stephen, is there any documents say that global makes timing worse? I didn't see this noticeable.

  • Local variable can't be accessed from inner class ???????? Why ??????

    Plesae help, help, help. I have no idea what to do with this bug.........
    <code>
    for ( int i = 0; i <= 2; i++ ) {
    for ( int j = 0; j <= 2; j++ ) {
    grids[i][j] = new MyButton ();
    grids[i][j].setBorder(but);
    getContentPane().add(grids[i][j]);
    MyButton sub = grids[i][j];
    sub.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    if ( sub.getState() == 0 ) {
         sub = new MyButton( (Icon) new ImageIcon(imageFile));
         if ( imageFile.equals("cross.jpg") ) {
              sub.changeState(1);
         else {
              sub.changeState(2);
    </code>
    The compiler complains that "sub" is in the inner class, which is the ActionListener class, must be declared final. Please tell me what to do with it. I want to add an ActionListener to each MyButton Object in the array. Thanks ......

    OK, now I changed my code to this :
    for ( int i = 0; i <= 2; i++ ) {
      for ( int j = 0; j <= 2; j++ ) {
        grids[i][j] = new MyButton ();
        grids[i][j].setBorder(but);
        getContentPane().add(grids[i][j]);
        grids[i][j].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            if ( grids[i][j].getState() == 0 ) {
               grids[i][j] = new MyButton( (Icon) new ImageIcon(imageFile));
              if ( imageFile.equals("cross.jpg") ) {
               grids[i][j].changeState(1);
              else {
              grids[i][j].changeState(2);
    [/cpde]
    Thanks for your advice !!!!!!
    Now the compiler says that i and j are local variables accessed from inner classes, needs to be declared final. How can I solve this then ???

  • Local variable without frontpanel object

    is there a possibility to create local variables without the need of a frontpanel object? I need zhem for program ccontrolontrol but don't want to show them to the user.
    Thanks a lot,
    greetings from Germany
    Karin

    Lynn, Marc, and "tbob",
    Thanks for your replies.  I detect the common theme of keeping my variables in bundles, but I'm not experienced enough to see how to apply this to my problem of communicating between parallel event handlers.  If you have the time and patience, I have attached a very simple example of what goes on in my program.
    I have three independent systems:  a motion system that carries around a microscope and digital camera.  Each system has its own event handler.  The motion system responds to user commands to move the microscope around, the microscope handler responds to changes in focus, zoom, etc, and the camera event handler continuously snaps pictures to provide a "live" image.
    But sometimes the loops need to talk to each other. For example, autofocusing is handled by the camera event handler, because it is based on image contrast, and that is the event handler that is acquiring the images.  So that means the camera event handler should take over the microscope during auto focus.  So the microscope event handler needs to be prevented from trying to get in on the act.
    So here is what the example illustrates:  some motion has just ended "normally".  The timeout event in the motion system signals the camera system to perform an auto focus (and waits for the focus to complete before allowing any movement).  The camera system signals the microscope system to perform a "stop" event, does the auto focus, releases the microscope from the stop event, and signals back to the motion loop that auto focus is done. 
    I, of course, thought this kind of thing was very clever!  More experienced Labviewistas may have other opinions....
    -Geoff
    Attachments:
    too many indicators.vi ‏24 KB

  • Create local variable using labview scripting

    I am trying to use labview scripting to create a control and a local variable for that control.  I want both the local variable and the control contained inside a case structure.  My problems are twofold:
    1. the local variable is left blank/unnamed
    2. the local variable is wired outside of the case structure, even though I set it's owner to be the same as the owner for the control (which is placed inside the case structure).
    The flat panel is there because I thought that my problem might be a result of the local var being created before the actual control, so this just forces the control to be created first.  The other thing I wonder about is the VI Object Class for the local variable.  I have tried 'Node' and Control->Boolean, but neither worked.
    I have attached a jpg of the code I'm talking about.  The picture on thetop is of the code in question.  The picture on the bottom is of the resulting code that's created....
    Can anyone offer any help?
    Thank you...
    Attachments:
    vi_scripting_lv.png ‏95 KB

    The reason your locals aren't tied to a control, is because you didn't make a local variable from any control.  Use the Boolean reference wire and wire it to an Invoke Node and select the Create >> Local Variable method.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Global and Local Variable

    Hi Gurus, I was unable to see where I can define local and global variables? I see that help.sap.com documentation but where do I create. All variables that I create, are global because, they are visible to all and they all can use it? Any help would be greatly appreciated.

    As far as I know, Variables are re-usable objects that are not dependent upon InfoProvider. When I look at this link
    http://help.sap.com/saphelp_nw04/helpdata/en/5c/8db07d555411d189660000e829fbbd/frameset.htm
    it talks about Global and Local variable? Is this different than what we use in Query Designer?

  • What is difference between local variable and property node ?

    What is difference between local variable and property node ?
    " 一天到晚游泳的鱼"
    [email protected]
    我的个人网站:LabVIEW——北方客栈 http://www.labview365.com
    欢迎加入《LabVIEW编程思想》组——http://decibel.ni.com/content/groups/thinking-in-labview

    To make things clear, here are two small examples that show how nasty locals and value properties can be to the naive programmer.
    - Open the diagram of the race condition.vi before running it and try to predict what will be the values of the two counters after the third run.
    - Use the Compare Locals Properties and Wires.vi to find out how slow locals and value properties can be (times 1000+).
    This being demonstrated, I must add that I use globals and value properties quite often, because they are often very convenient
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Race condition.vi ‏9 KB
    Compare Locals Properties and Wires.vi ‏18 KB

  • How to use local variable in member formula?

    Hi Expert,
    We would like to use a {local variable} in a member formula, so that it can pick up the prompt from webform upon save. Would like to know if it is possible to do? If so, what is the correct syntax?
    We attempted to use brace {scenario}, blacket [scenario], blacket with quote ["scenario"]. None of these work.
    We are using 11.1.2.1 version, EPMA, Hyperion Planning.
    Thanks in advance for your help!

    One other pointer. Where did you define your variable? Hopefully you went into Calc Manager and selected <Tools>, <Variables>. From there, navigate to your application or database. Right-click on your application or database and select "New". In the bottom panel, you'll need to select your Variable Type. Make sure you select "Member", and not "Members". You cannot pass "Members" (plural) to a web input form. Also, if you want to define a variable for a custom dimension, you'll need to do it at the database level. Standard dimension member variables can be defined at the app level. (Not sure why this is the case, especially when my custom dimension exists in all plan types . . . . )
    Anyway, hope this helps,
    - Jake

  • Default initialisation of member variables and local variables

    I don't understand why member variables are initialized with default values by Java.
    Objects are initialized with "null" and primitives with "0", except boolean, which is initialized with "false".
    If these variables are used locally they are not initialized. The compiler requires them to be initialized by the programer, for example "String s = null".
    Why? What is the use of that difference?
    And why are arrays always initialized with default values, no matter if they are member variables or local variables? For example String[] s = new String[10]; s[0] to s[9] are initialized with "null", no matter if "s" is a local or member variable.
    Can someone please explain that strange difference, why it is used? To me it has no sense.

    Most of the time I have to initialize a local variable
    with "String s = null" in order to use it because
    otherwise the compile would complain. This is a cheap
    little trick, but I think everyone uses it.
    I wouldn't agree with "most of the time". The only cases where it is almost necessary to do that is when the variable should be initialized in a loop or a try-catch statement, and that doesn't happen too often.
    If local variables were initiliazed automatically without a warning it would be a Bad Thing: the compiler could tell when there is a possibility that a variable hasn't been assigned to and prevent manymanymany NullPointerExceptions on run time.
    And you didn't answer me why this principle is not
    used with arrays if it is so useful as you think.
    Possibly it is much more difficult to analyse the situation in the case of arrays; what if values are assigned to the elements in an order that depends on run time properties such as values returned from a random number generator.
    The more special rules one has to remember, the more
    likely one makes errors.I agree, but what is the rule to remember in this case?

  • Data Acquisition - using local variables to write data to a file

    Hello,
    I am running a Data Acquisition vi (currently in LabVIEW 7.1 but soon to be updated to 8.2) that collects ~100 parameters of data from several sources contained in a while loop. The current configuration (which I did not write) uses very few subVIs and writes to ~100 local variables to store each parameter. It then reads all the local variables and builds an array of all the strings, converts then to a spreadsheet string, then uses the write characters to file function to append to a datafile. I am trying to clean things up and have came up with subVIs to collect the data from the following sources:
    8 serial port sources collecting btwn 8 and 20 parameters each
    ~15 thermocouple readings
    ~10 analog inputs
    ~20 parameters read off an ARINC 429 bus.
    I have come up with a subVI to read each of the sources and have placed the subVIs in the while loop. Each subVI outputs the data that it collects in array or cluster form. I was wondering how best to write each parameter to a CSV file at between 1 and 10 Hz. Should I write each subVI output to a LV and then read them off as was done before (the difference being that I have reduced the # of LVs to ~10 vs >100?
    I should add that precise timing is not that important, so if all the subVIs are not collecting simultaneously (which I understand that they won't be), it does not really matter.
    Thanks.

    Hi jilla,
    jilla wrote:
    What I think that you are saying is to turn the outputs of the 4 subVIs into inputs of a 5th subVI that writes to the data file. Correct?
    Yes.  It may sound like a fine-point, but I beileve it's better to create a VI specifically for formatting data - in your example, 4 arrays IN, a single string OUT.  Then write the string to file as a seperate operation.  GUI-displayed data can go through a similar transformation, the four arrays wired to a subVI which builds output-structures specifically for display.  It's a beginner's mistake to put lots of individual controls and indicators on the screen when groups of them are naturally related (in an object-oriented sense.)  Use clusters to group related controls - this will keep the diagram much cleaner.
    One more question: at what point (either # of data points or frequency of data collection) does it become necessary to use queues? Thanks.
    Well, there's not really a clearly definable "point".  I'd say if your update-rate climbs above 100Hz, or you witness poor program or system performance, then it's time.  The scenario you've described is a fairly simple acquire/display&log loop - and simple is good.   Then-again people can't see/react-to updates faster than about 10Hz - so it doesn't make sense to sacrifice performance - if performance becomes an issue.
    Re: queues:  Queues are sometimes used to buffer data that's "produced" in one place and "consumed" in another.
    Here, if/when logging data, you're logging with every DAQ.  I wouldn't recommend using a queue to transport data from a "DAQ loop" to a "Logging-loop" - those functions can be in the same loop.  Should/could a queue be used to get data from a "DAQ loop" to update the GUI at a lower frequency?  Sure, but a Notifier might be a better choice.   Further, in the (simple?) program you've described, you might use a case structure (True/False) to only update FP indicators every "X" iterations - a simple solution that doesn't require Queues or Notifiers.
    Cheers!
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)

  • How can I Change data in a type def control containing a Xcontrol with a local variable

    Hello
    I made a Xcontrol and I inserted this control in a type def.
    When I want to change the control's data with a local variable in a VI, the VI change nothing. The change of data isn't perform
    How can I correct this issue?
    Thanks for your help
    Solved!
    Go to Solution.

    Hello,
    What's your LabVIEW version ? Do you have a simple example program which demonstrates this behavior ?
    I found another discussions related to your issues with Xcontrols:
    updating type defs in Xcontrol Facade
    No Data Change event generated for a XControl in a Type Def
    XControl facede.vi 
    Hope this helps.
    Regards, 
    Steve M.
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Vidéo-t'chats de l'été : présentations techniques et ingénieurs pour répondre à vos questions

  • Control buttons in local variables

    hi,
    i have been trying to do this for a long time. i just never learned how to make it work. can someone please guide me?
    i have this program with many many local variables and i know that this forum absolutely hate LOCAL VARIABLES.
    I want to program this the right way, so can you guys please help take a look at my code and see what i can do in order to REMOVE local variables if possible?
    Best regards,
    Krispiekream
    Attachments:
    test.vi ‏768 KB

    does this work?
    i split up the zip file to 2.88mb each.
    i think there is a file size limit of 5mb
    can you rename test01.zip to test.z01
    can you rename test02.zip to test.z02
    Best regards,
    Krispiekream
    Attachments:
    test.zip ‏1078 KB
    test01.zip ‏2847 KB
    test02.zip ‏2847 KB

  • Reference to a local variable object returned by a method is alive?

    I have an instance method getEmployee().
    This method forms a local variable, Employee and returns it.
    public Employee getEmployee()
    Employee e = new Employee();
    e.setSNo(sNo+=);
    e.setMailBox();
    return e;
    There's another instance method in the same class that calls getEmployee() in this manner:-
    Employee newEmployee = getEmployee();
    newEmployee.printDetails();
    I want to know whether the employee returned by getEmployee() is still alive when we are doing newEmployee.printDetails().
    I am confused because in C, the lifetime of a local variable is limited only to the life time of the function. Once the function finishes, the local variable is considered garbage.
    How does it work in case of Java?

    No, It rarely has any use but can be used to unload things (from a cache for example). However I have never needed to do this. All I know is that finallizers can only be relied on to clear up memory. How or why you would do this is another question.
    The GC runs when memory is low (not any other resource). It calls finalizers when it clears up objects. Therefore the only thing you can reliably release in a finalizer is memory. Other resources can become depleted without heap being depleated so you can't use finalizers to relialy clean up non-memory resources.
    Anyway.
    some more info on escape analysis
    a compile time escape analysis
    http://www.excelsior-usa.com/pdf/StackAlloc.pdf
    This can handle some finalizers
    This does not handle finalizers (marks them all as GLOBAL_ESCAPE
    http://delivery.acm.org/10.1145/330000/320386/p1-choi.pdf?key1=320386&key2=0718563811&coll=Portal&dl=ACM&CFID=15151515&CFTOKEN=6184618
    bit more recent and about runtime optimization (finalizers not handled)
    http://ssw.jku.at/Research/Papers/Ko05/Ko05.pdf
    I don't think that not handling finalizers is too much of a problem. Most objects that will benifit from stackability are small objects anyway (especially the built in wrapper types). Most objects that have custom finalizers tend to be pretty complicated.
    matfud

Maybe you are looking for

  • Crash on Startup "scripting"

    I recently installed the Adobe production suite on my iMac 27in and everything was working fine and then yesturday I installed 8gb of ram and now upon startup of all my Adobe suite products I recieve a message that says "crash invoking "scripting" I

  • Expose Data 0f 1 Custom object group them based on another custom object

    1. Custom Object 2: Call Report 2. Custom Object 1: Customer 3. Account: Fields: Account Account Id Call Report Created Date Row Id Subject Owner Status Customer Customer Name Using Real Time Reporting-> Call Reporting Hide Display of Distributor Id,

  • Installing OBIA 11.1.1.7.1 on Windows 7 (64-bit). While applying platform patches it's failing.

    The final_patching_report.log is showing as follows: ----------START OF PATCHING REPORT------------------ * BIAPPSSHIPHOME Patching Report .......... Patch Succeded: fsclite_rel7mlr2_16424872.zip Patch Succeded: BISHIPHOME_11_1_1_7_0_GENERIC_130409_1

  • How do I remove unwanted entries in the Profile Manager window?

    Can anyone please explain how do you remove irrelevant entries in the Profile Manager dialog? Since I have both 4.0 and 3.6 installed,each with two profiles,I use to launch secondary profiles with the Profile Manager via a command line instead of a s

  • Closed captioning does not work

    Im trying to get closed captions onto my tape from FCP 7 using an .scc file. I go to print to tape and select the file but it does not show up. Im using firewir to a dsr-11 deck. Does anyone have a solution? Thanks