08-18-2009 08:29 AM
2 while loops are okay. 2 dozen means something is wrong fundamentally with your existing architecture.
You must rewrite it anew.
08-18-2009 08:30 AM
It sounds as though it is time to reorganize your program. With that many loops I suspect that the program has grown over time without any thought or planning given to the overall architecture.
Queues are good ways to pass data between loops, but you will have a lot of queues with as many loops as you have. Action Engines may be a better choice, because they can be read many places.
Lynn
08-19-2009 07:38 AM
There are five items you can use to replace local variables - in order of preference:
08-19-2009 07:59 AM
DFGray wrote:There are five items
Where is the fifth?
But I know it is NOT Property node.
08-19-2009 08:03 AM
08-19-2009 08:33 AM
08-19-2009 08:56 AM
DFGray wrote:There are five items you can use to replace local variables - in order of preference:
I have deluged you with enough information. Good luck!
- Wires - never use a local when a wire will do
- Shift registers - fast and local
- Data value reference - new in LabVIEW 2009
- Single-element queue or action engine - these are equally good, interchangeable in most situations, use the one which fits your programming style and circumstances (I use both but prefer the former for most things)
The Single-element queue might be overkill for replacing local variables which have been tested and do not have race conditions. If the code is written in such a way that race conditions can't happen, then I think the native functions Notifier or Queue would be a better choice for the sake of simplicity. This is just an opinion, and is notwithstanding the Data value reference option.
08-20-2009 03:18 AM
Got about two dozens of while loops running in parallel and bunch of data needs to be flowing back and forth between them. |
|
08-20-2009 09:33 AM
You are correct. To write to a single-element queue, dequeue first, change or replace the value, then enqueue. Reading is similar. Dequeue, then enqueue. Since the first act is always a dequeue and there is only one element, this serves as a global mutex, also giving you atomic operation properties. Remember to enqueue or other readers will halt. The fact that you have a "mutex" also opens you up to deadlock possibilities. The safe use of global data is a minefield. Let us know if you need more help.
P.S. The fourth and fifth methods are listed in my fourth item. They are distinctly different methods, but are equally useful, so I grouped them together since the list was by order of preference.
P.P.S. I do not consider the replacement of locals (or globals) by data value references, single-element queues or action engines to be overkill in any situation, provided the options above these in the list are not useable. I would much rather have the flexibility of encapsulating code into subVIs at will and controlling access to the variable. This is not an option with locals. However, this is a personal preference. My code tends to be extremely modular.
08-20-2009 09:48 AM