03-02-2023 02:35 AM - edited 03-02-2023 02:43 AM
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?
03-02-2023 03:09 AM
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…
03-02-2023 11:05 AM - edited 03-02-2023 11:07 AM
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.
03-03-2023 03:42 AM
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!