LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Weird cluster update problem

Deal all,

 

 I am working on a control program and have a weird cluder update problem. Try to figure out what's wrong for a few days and not success.

 I hope someone here could help. I attached my code here and simple instruction for test is included in the code.

 The Main-code-to-test.vi is the code to run and test.

 

 

 Thank you so much.

 

 Lee

0 Kudos
Message 1 of 6
(2,322 Views)

You have a race condition due to the abuse of local variables.  You update the local variables and terminals of the E# clusters had multiple locations.  It is a race as to which update executes first and thus "sticks" with that value in the indicator on the front panel.

0 Kudos
Message 2 of 6
(2,308 Views)

Thanks a lot for your replay but I am sorry I can't understand what is actually wrong from your message.

Could you please point out more clearly why the update of local variable (E1 cluster) cause the race condition?

 

Thanks.

 

Lee

0 Kudos
Message 3 of 6
(2,294 Views)

You read the control in multiple locations.  You change a value in the cluster in one location.  You than write the values back to the control at multiple locations.  Depending on the order of execution of parallel pieces of code that have no defined order of execution, one write to the local variable will overwrite the values that are happening in other locations where the local variable is being written to.

 

I suggest searching the forums for the phrase "race condition" to see more details about this topic.

 

Also Why some people say Local Variables are bad....

0 Kudos
Message 4 of 6
(2,287 Views)

OK, thanks. All of the "write value" of E1 cluster were put in one event structure (No race can happen between them) except one in the central top while loop.

There might be a potential race between the one in while loop with the event structure. But the problem is the "race" happened so offen and don't look like caused by a race.

 

Still don't understand why the value would go to the initial value, how? 

0 Kudos
Message 5 of 6
(2,270 Views)

That is the race.  You are reading the current values in the center top while loop, then proceeding to writeh them back to the same control.  (Why??)

 

In your event structure, you are reading the values, changing them and writing them back to the same control.

 

On order for your new updated values to stick, you have to get lucky enough that the event finishes executing and writes the updated value in the slight fraction of time after the "old" data is written to the local variable in the upper while loop and before the loop iterates and the local variable is read again in that upper while loop.

0 Kudos
Message 6 of 6
(2,265 Views)