LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shared variable for Error not working

I have three parallel loops. Each can produce an error. I want ALL loops to be stopped if any has an error. 

 

I tried to solve this with a shared variable for the error wire. However, as you can see from the probes in the screenshot, the TRUE value when an error occurs is used to stop the loop in which the error occured, but then it becomes FALSE again.

 

How to stop parallel loop on error the clean way?

 

 

 

errortrigger.PNG

0 Kudos
Message 1 of 4
(831 Views)

Hi faul,

 


@UL-00 wrote:

I have three parallel loops. Each can produce an error. I want ALL loops to be stopped if any has an error. 

 

I tried to solve this with a shared variable for the error wire. However, as you can see from the probes in the screenshot, the TRUE value when an error occurs is used to stop the loop in which the error occured, but then it becomes FALSE again.


So there are 3 loops, all writing to the same SharedVariable!?

Have you ever heard about "race condition" before?

 

Whenever there is a shared resource used in parallel you may run into race conditions: you cannot determine which access does win…

 

Why do you even need to access the same SharedVariable twice inside the same loop? Did you run out of wires???

 

One of many possible solutions: replace the SharedVariable by a FGV (functional global variable aka AE=action engine): input the error cluster, output a TRUE/FALSE value. Inside the FGV you can OR an internal state with the new error input to handle your problem…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(817 Views)

As always, we cannot debug truncated pictures of some random code, but there is an obvious race condition where "44" gets read way before "43" gets written.

 

If three loops write to the same variable, whoever wrote last determines the state.

 

You need to attach the entire VI for us to give further advice.

0 Kudos
Message 3 of 4
(801 Views)

Thank you very much guys. I now understand that it's possible that the value written into a shared variable by one loop might never get read by another loop because of race conditions.

 

@Gerd: I used the same shared variable twice in a loop because I hoped it would solve my problem, but it didn't for the reasons I now understand 😉

 

I will look into FGV!

 

0 Kudos
Message 4 of 4
(772 Views)