The Daily CLAD

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

Re: Dataflow with Sequence Structures

SercoSteveB
Active Participant

Given an intial value of 0 for 'Multiplier', what are the possible values of 'Numeric Value Out' following execution of the VI?

Dataflow Sequence Structures.bmp

a) 0 only

b) 64 only

c) 0 or 64

d) Undetermined

Comments
Kumarhatti
Member

Ans is 😛

Neelamma
Member

ANS: B

Musale
Member

Answer is B.

nmpundlik
Member

ANS: B

crossrulz
Knight of NI

D, nope C.  Sorry, jumped the gun on that one.


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

Ans is B

2verb
Member

A very nasty gotcha.

I agree with crossrulz. C because order of execution is not guaranteed.

Not applicable

I vote for C as well. This is a nasty race condition.

Not applicable

Sequence Structure Race Condition Screenshot.png

Run the code shown above to 'force' the race condition and get 0 as the result.

crossrulz
Knight of NI

Here's the code I used to get 0

Dataflow with Sequence Structure.png


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

C. Oh how I love race conditions...

Edit:  I think I'm going to change to D.  I think it is possible the an iteration or two of the while loop could be execuited before the sequence starts.

Not applicable

Another CLAD type question; Referring to crossrulz block diagram, what does a Wait function with an input of 0 cause LabVIEW to do and in turn create the race condition?

crossrulz
Knight of NI

That was probably Steve's question for tomorrow.  If not, maybe it should be.

BTW:  Steve, you need to start using the Code Capture Tool.  It'll turn your code into nice snippets (like mine) instead of creating references and making a mess.


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

Answer is B

SercoSteveB
Active Participant

Awesome thread.

I am not aware of the code capture tool, when was it introduced? I need it.

For clarity then, what would be the answer if I had wired the output of the While loop to the first frame of the sequence structure?

crossrulz
Knight of NI

SercoSteveB wrote:

I am not aware of the code capture tool, when was it introduced? I need it.


                   

It has been around for awhile.  It is available through the LabVIEW Tools Network and VIPM.

SercoSteveB wrote:

For clarity then, what would be the answer if I had wired the output of the While loop to the first frame of the sequence structure?


                   

That's an obvious A


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

SercoSteveB wrote:

For clarity then, what would be the answer if I had wired the output of the While loop to the first frame of the sequence structure?

No doubts that would be A.

crossrulz
Knight of NI

MrStevenUND wrote:


                       

C. Oh how I love race conditions...

Edit:  I think I'm going to change to D.  I think it is possible the an iteration or two of the while loop could be execuited before the sequence starts.


                   

Remember that the initial value for the multiplier is 0.  So if any iterations got done before the first frame of the sequence structure, you will constantly have 0*X, which is 0.  In short, you get 0 if any iterations happen first or 64 if the sequence structure frame is performed first.


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
SercoSteveB
Active Participant

So the Code Capture Tool is an add-on? I will definitely check it out.

sumapatil
Member

a

sumapatil
Member

Answer is B

Not applicable

sumapatil,

Can I suggest you read all the comments that have been posted about this question. General opinion is that the answer is C, because of a race condition. Take a look at the code samples people have posted.

David.

jagadishj
Member

suma

        don't choice two options choice only one option

jagadishj
Member

Ans is B

mini09
Active Participant

B for the steve post.. 0 for David Corney and crossrulz,,,

MrStevenUND
Member

crossrulz wrote:

MrStevenUND wrote:

                       

C. Oh how I love race conditions...

Edit:  I think I'm going to change to D.  I think it is possible the an iteration or two of the while loop could be execuited before the sequence starts.

                   

Remember that the initial value for the multiplier is 0.  So if any iterations got done before the first frame of the sequence structure, you will constantly have 0*X, which is 0.  In short, you get 0 if any iterations happen first or 64 if the sequence structure frame is performed first.

yup... that's what I get for second guessing myself and not looking back at the diagram before changing my answer...   Thanks Crossrulz.  I'm back to C.

clendon.gibson@canrig.com
Member

Now let's use semaphores to fix it!

Not applicable

gnshmrthy , the answer is C. The code in the question will return the value 64, 99.99999...% of the time, but there is always the chance it will return 0. The solutions crossrulz and I presented simply make the odds of the race condition occuring lower. This is a really nasty race condition that could go undetected for millions (even trillions) of iterations and then one day it will happen.

RAMESHB
Member

Hey! suma how its answer a can you explane..

SercoSteveB
Active Participant

Could we use a single structure to get the desired order?

sequence_structure.bmp

....gives 0.  Switch cases 0 and 1 for 64.

SercoSteveB
Active Participant

Race conditions are always a HOT topic.

Not applicable

For me this question has highlighted the problem with overuse of variables and the sequence structure. Variables break dataflow, which is their intended purpose when used correctly. From my vantage point the the primary use for sequence structures is on the RT and FPGA targets where we need to enforce execution order while minimizing the number of wires (error clusters use precious FPGA gates); other than that I avoid them at all costs.

I would say this is a great example of how to write bad code in LabVIEW. I think it is important for those who subscribe to this Blog to fully appreciate what can go wrong when you don't use wires to enforce execution order. I am not saying don't use variables and the sequence structure, but be aware that a race condition can go undetected until it is too late. A good code review with an experienced developer may catch a problem like this.

This is a great question. There are others you have posted, Steve where I have built the code and thought "I never knew that". Keep up the good work.

SercoSteveB
Active Participant

I couldn't agree more.  I wont let my guys use sequence structures in anything other than FPGA.  I have it written into our site coding standards.

We have even gone so far as to create some of our own VIs that simply wrap up the functions provided by NI.  This allows us to maintain the dataflow, usually using the error cluster.

Maintain the Dataflow.png

MrStevenUND
Member

SercoSteveB wrote:

I couldn't agree more.  I wont let my guys use sequence structures in anything other than FPGA.  I have it written into our site coding standards.

We have even gone so far as to create some of our own VIs that simply wrap up the functions provided by NI.  This allows us to maintain the dataflow, usually using the error cluster.

Maintain the Dataflow.png

There is also the express VI, "Time Delay" that does the same thing you show.  It uses slightly more memory space because the input is Seconds as a double, and inside has a *1000 going into the "wait (ms)" vi.  It is one less VI for you to manage on your own as it comes with LabVIEW.

SercoSteveB
Active Participant

MrStevenUND wrote:

There is also the express VI, "Time Delay" that does the same thing you show.  It uses slightly more memory space because the input is Seconds as a double, and inside has a *1000 going into the "wait (ms)" vi.  It is one less VI for you to manage on your own as it comes with LabVIEW.

I tend to avoid Express VIs and I can't really offer a good reason as to why.  Nice one Steven I really must open my mind to other solutions.

If you open your mind too much, your brain will fall out.

SercoSteveB
Active Participant

Answer: C (probably).  Awesome thread guys. 

Nice content DavidCorney, MrStevenUND & crossrulz, thanks.

Watch out for questions with sneaky race conditions coming soon to a browser near you.

VSC
Member
Member

By judging and analysing the qustion at hand i would like to go with 'B'. And i also agree with the other replies but that condition will take place only with delay and input as '0' in the sequence structure's first case.

crossrulz
Knight of NI

VSC wrote:


                       

but that condition will take place only with delay and input as '0' in the sequence structure's first case.


                   

Not necessarily.  You just haven't ran into the case were it does yet.  It will be very rare, but it could.


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

Ans is B

mini09
Active Participant

Can you give me some related documents how to find the race condition in a program just by looking the code?

2verb
Member

Hi gnshmrthy,

I am not aware of a good race condition document. I know for me, the problem of a race condition became obvious once I set up the code in LabVIEW and stepped through it.

The first thing to remember is that LabVIEW is a dataflow programming language. This means that each block will execute when all of its inputs are satisfied. When two or more blocks have their inputs satisfied at the same time, then the order of execution is unpredictable. If you have blocks where the order of execution is unpredictable, but the order of execution changes the outcome, then you have a race condition.

The clever bit about Steve's example is to trick us into thinking that the entire sequence structure will wait until its inputs are satisfied. But it won't. Each frame of the sequence structure can run anytime provided that the previous frames have run and their inputs are satisfied. The first frame of the sequence structure has no inputs. It may be the first thing to run in the diagram, or the while loop may run first.

Once you know these things about hwo LabVIEW works, it becomes obvious this is a race condition.

I hope that helps.

mini09
Active Participant

Thanks 2verb that waas an great note to know....

ashwinilele
Member

C

debapriya_maji
Member

So the final answer is 'c' right?

mohamedtanveej17
Member

hi everyone 

 in the first sequence of sequence structure which element is used as multiplier whether a local variable?