LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

what's the best way to prevent 2 loops accessing to one variable at the same time?

Hello everyone, Happy new year to all you first!
I have a question about preventing two loops accessing a batch of shared variables at the same time in labview.
Right now I am using a 3 frames case in each of the loop. In the first frame, a local boolean variable is set to true representing start of access. In the 2nd frame, the variables are accessed, In the 3rd frame, the local variable is set to false representing end of access. So by check the local boolean variable in the other loop, it will tell the other loop if or not to access the variables.
My other thought is to use a queue to do same job.
My question is, comparing with a single bit-level operation cmd in a traditional programming, these 2 labview approaches seems lower efficiency and it's my concern as my loops executes very fast.
So I am looking for better idea to do the job. Any comment or idea is welcome!
 
Feilong
 
0 Kudos
Message 1 of 9
(2,783 Views)
i have a bit of troubles understanding what you are doing:
are you using the same set of locals in all 3 loops? if yes, i would propose to rethink the way you program all together.
it would help if we could see the code tough.
in general, the utilisation of locals is very prone to race conditions, and is the wrong approach when sharing information between different instances.
as a fast workaround you can use Actions engines (AE). they have also limitation when sharing data, but you can use very easy protection mechanism in the AE itself.

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
Message 2 of 9
(2,775 Views)

Another option is the use of semaphores.

Depending of your code style....

Message 3 of 9
(2,770 Views)

Another way is to use functional globals.

Functional globals are SubVIs with a while loop running once and a shiftregister to store the value. Another parameter is the command what to do like "Set", "Read", "Increment" ...

Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 4 of 9
(2,740 Views)


waldemar.hersacher wrote:

Another way is to use functional globals.



or in Bens's language an Action Engine, see above Smiley Wink
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
Message 5 of 9
(2,736 Views)

Hi Gabi1,

 

I was out of  the forum for nearly a year recovering from a burnout syndrome so I didn't keept up with the things going on.

But anyway thank you for pointing this out.

Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 6 of 9
(2,733 Views)


I was out of  the forum for nearly a year recovering from a burnout syndrome so I didn't keept up with the things going on.


wireworking related? you are back, thats what important :)
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 7 of 9
(2,709 Views)

Sorry to hear about the burnout Waldemar. I hope it was not railroad related. BTW: we have have made progress and have started to assemble the steel mill (or in Pittsburhese "still-mill").

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 9
(2,700 Views)
Dear Gabi1 and Ben,

it was the general amount of work, making the CLAD and CLD, having a 10 hour workday and the personal interests. I stopped the LV8.5 beta, the forum here and the forum of the railroad. The railroading brought me up again even with wireworking (scroll down for my post) for it. I started scheduling my day and week and if it is not done within the scheduled slice it will get another slice sometime later. Starting next week Tuesday and Thursday will be my regulary time here in the forum.

Maybe someone has to split the thread and put the last posts into the Breakpoint under something like "The recovery of Waldemar". Smiley Happy
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 9 of 9
(2,689 Views)