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: 

Is this a SCTL race condition?

Solved!
Go to solution

Dear all,

 

So the real code is of course more than this, but basically - can I do this (safely?) in a SCTL?

cbutcher_0-1600075405049.png

This will sit in a SCTL on a shift register (in the "Wait with CONVST Low" case), and I'll unbundle (via accessor) the "Next State" at the beginning of the SCTL and then pass that to the case structure.

 

Basically the same code already exists using a combination of shift registers, so I'm hopeful that this is fine, but some brief crisis of (non)confidence has overtaken me and I want to check that reading and writing the same value (Wait Remaining, in this example) in a SCTL isn't going to lead to unexpected behaviour due to a race condition here.

 

The motivation is to move more complicated logic into a nicer abstraction and prevent the addition of another half a dozen shift registers to my SCTL to handle more complicated situations than this one, but they have basically the same code - unbundle, check some things, add/subtract etc, bundle the new values for those elements.


GCentral
0 Kudos
Message 1 of 6
(1,329 Views)

Updating the same value (Wait Remaining) in the way you have developed will not be creating any race condition since it works sequential.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
Message 2 of 6
(1,324 Views)

Encapsulation, one of the benefits using OOP, the data belongs to a class, you can't unbundle or access the data outside the class without your consentment or by using accessors.

0 Kudos
Message 3 of 6
(1,298 Views)
Solution
Accepted by topic author cbutcher

When compiled to the fabric, almost all of that (the unbundle and bundle) are just wires, eventually going to a holding register.  So I see no dangers in this code from being in a SCTL.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 6
(1,287 Views)

I'd always use <=0 for the compare, not =0.

 

What if the class data is somehow reset (forgot to wire a tunnel)? Or if some other (future) function decreases the Wait Remaining or sets it to 0 (if it's done waiting). The Wait Remaining will probably become 0... Then you get 0-1=-1, and =0 will fail. You'll be waiting very, very long.

 

There'd be no race condition, unless there's a serious bug in LabVIEW.

Message 5 of 6
(1,284 Views)

Curious, I decided to test.

My actual code worked fine, and then for the sake of simplification I also tested the following:

cbutcher_0-1600085677305.png

 

Top loop:

cbutcher_1-1600085715310.png

Bottom loop:

cbutcher_2-1600085739419.png

 

Output as expected:

cbutcher_3-1600085779194.png

 

 

 


GCentral
0 Kudos
Message 6 of 6
(1,282 Views)