The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Looping Additions: Property Nodes and Shift Registers

SercoSteveB
Active Participant

Given an initial value of 1 for Numeric Value In; what is the value of Numeric Value Out following execution of the VI?

Looping Additions.bmp

a) 5

b) 6

c) 7

d) 8

Comments
crossrulz
Knight of NI

D

But just so people know.  If I see you write code like this, I will majorly yell at you in a code review.  Should be using shift registers all the way.


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
VSC
Member
Member

i agree with D. the loop count is 3 thus the loop goes for 0,1,2. and the resultant for number value is =4. therefore when the loop is satisfied the final addition results to 4+4. thus the answer is D.

MrStevenUND
Member

ANS: D 

Edit: Steve, You are beeing sneaky.  The answer is E: none ALL of the above/undeterminable.  You have a race condition here....  When does the control-to-addition happen compared to the FOR loop?  I believe most of the time, you'll get A, but this is not guaranteed.

I second crossrulz's comment.  This is a horrible way to code (EDIT: not just the race condition that I didn't initially see).  The sad part is I have seen some code like this on projects I have inherited (EDIT: minus the race condition)...

SercoSteveB
Active Participant

What is this international pick on Steve day ?

I hereby promise to use good programming style ; I reserve the right to sometimes deviate a little (or more than a little) to get my point across.  

Question delivery is key.

nmpundlik
Member

Ans is A.

Asha_Nagaraj
Member

Answer is A.

crossrulz
Knight of NI

Good call MrSteven.  I fell into the classic "what are they trying to test" instead of thinking it clearly.


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
Not applicable

I am going with answer A.

Maybe I am missing something, but I don't see a race condition MrStevenUND mentions.

crossrulz
Knight of NI

DavidCorney wrote:


                       

I am going with answer A.

Maybe I am missing something, but I don't see a race condition MrStevenUND mentions.


                   

You don't see the control outside of the FOR loop and the property node writing to it inside of the FOR loop?


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
Not applicable

Are we stating that there is a race condition, because you could modify the control while the loop is running? My bad to assume that the user would not change the control once execution starts (or have time).

As an aside, is anyone else having to log in to the community site every time they open the page?

crossrulz
Knight of NI

DavidCorney wrote:


                       

Are we stating that there is a race condition, because you could modify the control while the loop is running? My bad to assume that the user would not change the control once execution starts (or have time).

No.  It is a race condition because when will the control terminal be read for the final addition.  It is being read and written to inside of the FOR loop and therefore who knows what value will be read from the terminal when it does decide to read.


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
Not applicable

Okay, got it. I need more coffee. Thanks!

GayatriT
Member

Ans is A.

SercoSteveB
Active Participant

Answer: A (most likely).   Nice one nmpundlik, Asha_Nagaraj, DavidCorney & GayatriT

Good spot MrStevenUND.  Yep it does contain a race condition, but I prefer to think of it as a Dataflow Paradigm question.  Another one of those little gotchas that is easy to fall into if you are not concentrating (or concentrating more on the coding style eh GM ?)

adiveppa
Member

ans is A

jagadishj
Member

A is the write answer.

mini09
Active Participant

wow wow my first thoght was B later when I try with the code go with A.... Nice one. what are the different race conditions possible in LabVIEW and how do we say it is an race condition.

LordNobady
Member

race conditions are mostly possible with writing to variable ( global's and locals ) and writing to property node's when any of them is done watch for race conditions.

other interesting points ( data flow ) are reads from variables, property nodes or front panels. thy can ( and mostly will ) happen as soon as that part of the code is executed.

this is interesting mostly for stop buttons in loops.

if the data can be changed (programaly) before the point the value is required it can give unexpected results. and in a lot of cases can be called a race condition.


Learning LabVIEW since January 2013
ashwinilele
Member

Ans is A

ashwinilele
Member

Value is read by control then it's node value just like variables . So ans is A

skian
Member

A),

This was a great question. I guess the answer is  it is better understood while following the data when highlighting execution is on.