07-19-2006 12:42 PM
07-19-2006 12:52 PM
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!
@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?
07-19-2006 01:40 PM
07-19-2006 02:26 PM - edited 07-19-2006 02:26 PM
@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
07-19-2006 02:37 PM - edited 07-19-2006 02:37 PM
Message Edited by MattH on 07-19-2006 02:38 PM
07-19-2006 02:44 PM
07-19-2006 02:48 PM
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.
07-19-2006 03:10 PM
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.
07-19-2006 03:42 PM
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
07-19-2006 04:31 PM
@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!