From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid race conditions??

Solved!
Go to solution

Hi, ive been doing Labview for 10 years now. And its the first time ive come across or its effected my code. I have a lot of code that executes at the same time. And done for years, any good practice to avoid this ever happening again??

 

Stu

0 Kudos
Message 1 of 17
(7,458 Views)

Make sure operations that are dependant on each other are wired/sequenced so they're forced to execute in order. It's often easiest to control through error wires.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 17
(7,449 Views)

Avoid variables (at all costs?!). Lock critical sections.

 

How to do this:

Implement an appropriate architecture.

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 3 of 17
(7,440 Views)
You can use the semaphore VIs under the synronisation pallete to protect specific sections of code. Or, if you are using a queued/statemachine architecture you normally handle race conditions through a good design
David
www.controlsoftwaresolutions.com
0 Kudos
Message 4 of 17
(7,432 Views)

Hi Stu!

Maybe you could post a picture of your diagram. Thus, it would be easier for us to help you.

 

Best regards

Leo

0 Kudos
Message 5 of 17
(7,412 Views)

Hi, my entrire llb is here on this thread. Basically its do with upper left loop which reads the opc mass spec read. I'm trying to find what is interefering with it?? giving out of sequence results.

 

http://forums.ni.com/ni/board/message?board.id=170&thread.id=471306
0 Kudos
Message 6 of 17
(7,408 Views)
Could you resave it in 8.2? 🙂
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 17
(7,390 Views)
Solution
Accepted by topic author stu22

I spent an entire course on race conditions and concurency in grad school, and to avoid race conditions you have to understand why they arise.

Race conditions occur when multiple concurent or parallel processes access a shared resource.  Furthurmore it is mostly troublesome when 2 or more threads/processes are activly modifying a resource.  So first identify the candidates for this when architecting your application.  If you only have one thread you should be safe (although this is getting more fuzzy since there is the ability to run in parallel).  Next is there any resources/variables that are needed in 2 threads at the same time, and if so do you modify the value in one or more threads.  If so you have to deal with synchronization.

 

Traditionally you talk about semaphors, locks and mutexs.  All methods for locking critical code (ie resources that are possible race condition sources).

 

BUT WE ARE IN LABVIEW.  Labview has one easy method that could be easier to use, the functional global.

since vis that are not marked for reentrancy are essentially nice way for protecting data and locking your critacal sections.  Only one thread can access and or modify the data stored in the vi at a time.  Other threads will block and wait on the resource.

This was much harder to implement in c.

 

Either way the way you deal with race conditions is to

1.  Identify critical sections and resources that can cause race conditions (usually shared resources with multiple writers)

2.  Lock the resource until done (avoid deadlocks while doing so-but this is another discussion)

 

Unlike traditional bugs, concurent bugs are more random and very difficult to reproduce/test for so you will have to deal with them in the design architecture stage.

 

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 8 of 17
(7,379 Views)
0 Kudos
Message 9 of 17
(7,376 Views)

Functional Global is a type of Action Engine (AE) as I discuss in this Nugget.

 

That nugget discusses this image

 

 

in the discusion of how the critical section is protected.

 

Ben 

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 17
(7,370 Views)