LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"case structure" execution completion

Assume a while loop with multiple case structures in it.
Assume that there are no wires connecting any of the case structures.
 
Is it guaranteed that once execution enters a case structure that all VI's and variables modified by the structure will be completed prior to another case structure being entered?
I am not using any event structures.
 
 
Using LabView 7.1
 
Thanks in advance
0 Kudos
Message 1 of 10
(3,185 Views)


@jspaarg wrote:
Assume a while loop with multiple case structures in it.
Assume that there are no wires connecting any of the case structures.
 
Is it guaranteed that once execution enters a case structure that all VI's and variables modified by the structure will be completed prior to another case structure being entered?

No, this is not guaranteed. If there is no data dependency between the case structures, both can execute in paralell. Try it yourself: Place a while loop with a small wait in each case structure and display the iteration terminal of both. Both will increment!
Message 2 of 10
(3,180 Views)
You could, I assume, disable multithreading and see if this works the way you desire.
Tools Menu >> Options >> Performance and Disk
Uncheck the box for multithreading.

You will have to open and close LabVIEW to see the change.
0 Kudos
Message 3 of 10
(3,177 Views)


@MattH wrote:
You could, I assume, disable multithreading and see if this works the way you desire.

NO! This has absolutely nothing to do with multithreading, so disabling multithreading will not "solve" anything. 🙂

jspaarg, please explain what you want to do and why something like this is important. Most likely, you're chasing the wrong ideas based on some misconceptions.

In order to efficiently write LabVIEW programs, you need to familiarize yourself with the basic details of dataflow programming. If you require a certain execution order, simply create a data dependency.

Just limit your use of local variables and the rest will fall into place naturally. Always go with the dataflow!  😉


 

Message Edited by altenbach on 07-19-2006 12:28 PM

Message 4 of 10
(3,163 Views)
While I hate being wrong... I thought about it some more and you are absolutely correct.
I don't program this way and just didn't put much thought into it. I was trying to solve one small problem (the possibility of two cases accessing data at the same time) while it now seems (after I read the description more closesly, that jspaarg wants a group of code to execute independantly before returning control to the other cases...

this sounds like he/she needs a state machine!!!

Message Edited by MattH on 07-19-2006 02:38 PM

0 Kudos
Message 5 of 10
(3,150 Views)
"hate being wrong..."
 
Do not let it get you down. After all it was The Grand Wizard" talking and it is an honor to be corrected by him (or tst).
 
On the positive side, you probalbly have a much better "model" in your head to use the next time you need to remeber this.
 
Ben
 
PS A state machine is not required yet. Just a wire.
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 10
(3,141 Views)

Thanks so much for the interest altenbach.

When dealing with embedded code, I tend to be the one that others ask for assistance.  However, with LabView, I often operate with misconceptions because of the mental paradigm that I have acquired with over 20 years of embedded.

That said...

I am writing some medium-sized applications that have automatic inputs coming via an RS232 link.  The RS232 is connected to an RS232<->CAN convertor.

There are also a number of front-panel user controls; the most important of which is a multi-column listbox.  The listbox is used to highlight a device on the CAN bus to control.  Status is automatically reported by all devices on CAN and the list box is continually updated with the status from the devices.

While I can easily wire through boxes to create data dependencies, this gives me two aesthetic problems:

1: The block diagram tends to be extremely long from left to right:

2: More importantly, there are wires everywhere.  Even if the wires are kept to a minimum it still winds up being spaghetti code (in looks if not implementation).

 

I have gotten into the habit of using local variables (I realize that the code is not as efficient, but I believe it is far more readable).

The issue that prompted the question is this:

I have a boolean called "Update" which can be set by a number of different operations (all of which are in case structures).  The problem is that if "Update" gets set true prior to the data that needs to be updated is modified, then the update case structure could be activated and perform an update on data that is not yet ready.

The simple solution (without re-architecting) is to just put a flat sequence structure in the case structure and put the update in the last one.

I am sure that you have better ideas on how to do this.

Hopefully I have explained this sufficiently that you can offer some advice.

Thanks again.

 

 

0 Kudos
Message 7 of 10
(3,141 Views)

Apologies for singling out altenbach (is there a way to edit your own thread after it is submitted).

I had the last post sitting on my computer for over an hour before actually submitting it.

More advice came in since then.

Sorry and thanks.

 

0 Kudos
Message 8 of 10
(3,124 Views)

From the added info you posted, it sounds like the sequence structures will solve your problem.

Also, I now withdraw my previous comment about the state machine being over-kill.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 10
(3,114 Views)


@jspaarg wrote:
1: The block diagram tends to be extremely long from left to right:
2: More importantly, there are wires everywhere.  Even if the wires are kept to a minimum it still winds up being spaghetti code (in looks if not implementation).

Hmm, maybe you're doing something wrong. A local variable is a 2D diagram object with a length depending on the name of the control/indicator and thus takes up significant horizontal and vertical diagram space. A wire connecting two objects is only a few pixels and takes up much less diagram space.

If there are many wires always going to the same places, bundle them together.

Also have a look at my old post here: http://forums.ni.com/ni/board/message?board.id=170&message.id=112401&query.id=0#M112401


@jspaarg wrote:
I have gotten into the habit of using local variables (I realize that the code is not as efficient, but I believe it is far more readable).

A diagram peppered with local variables is significantly less readable in my book, because there is no way of tracking where the data goes, where it comes from, how stale it is, and what other part of the diagram modified it last. In contrast, on a diagram withhout locals, it's just "follow the wire". You know exactly where the data comes from! 😄

Line based code executes sequentially. If you translate each statement into labview using local variables, it is the same as completely scrambling the statement order.

Dataflow has huge advantages, even more so in the future where multicore, multiCPU, etc. systems become more prevalent. I would suggest you fully embrace it and "go with the (data)flow". Why first break dataflow with locals, then enforce dataflow with sequences (...and then argue that it makes the diagram smaller and more redable. ;)). Something does not quite add up. 😮


@jspaarg wrote:
The problem is that if "Update" gets set true prior to the data that needs to be updated is modified, then the update case structure could be activated and perform an update on data that is not yet ready.

You just described a typical "race condition" directly caused by the use of local variables. These are difficult to troubleshoot and track down.

It is hard to make more detailed suggestions without seeing the code, but I am sure there is a better way. Maybe you should take a few steps back and look at the diagram. What can be improved? Is there repetitive code that could be replaced by a subVI? Are logical execution traces aligned horizontally or does everything go criss-cross?

Good luck!

Message 10 of 10
(3,100 Views)