07-19-2005 05:41 AM
07-19-2005 05:53 AM
Hi,
You can use, for instance queues to do that.
07-19-2005 05:54 AM
07-19-2005 07:14 AM
I like using queues, notifiers have a few limitations, the do not work remotely (probably not a problem) and notifiers do not buffer sent messages, acting like a lossy queue. I would avoid the temptation to use local or global variables since race conditions occur in concurrent loops. Queues are surprisingly easy to use in labview and have saved me many times. I am not sure about overhead associated with queued communication but I have never had a problem using them even in DAQ or processor intensive application. In addition you can name the queue which allows easier debugging of error conditions.
-Paul
07-19-2005 07:16 AM
07-19-2005 07:45 AM
07-19-2005 07:48 AM
07-19-2005 07:50 AM
07-19-2005 08:02 AM
Hi esa_paranoid,
I agree with falkpl who wrote
"I would avoid the temptation to use local or global variables since race conditions occur in concurrent loops".
1) Queues are fast and efficient. Good if your data starts in one or more places and end ups in one place. Example: Commands to a "robot controller" that has to respond to requests from more than one client. These do NOT work across networks with multiple machines.
2) LV2 Globals, Not as fast as queues but handle multiple readers. Example: Multiple tasks need to know the status of safety interlocks. Can be shared across multiple machines.
Ben
07-19-2005 11:30 AM
"I would avoid the temptation to use local or global variables since race conditions occur in concurrent loops".
Race conditions occur when using locals within one loop. When using parallel loops, local variables are an excellent and very easy way to send data from one loop to another. Of course, improper programming could always cause problems no matter what you use, queues or locals. Here is an example of using a local properly between two loops. If you want both loops to stop when the user presses the stop button, one loop contains the stop button and the other loop contains a local of the stop button. Nothing wrong with that. Using queues instead of locals to send data to another loop is more complex, harder to code, yet it performs the same function and the same risks are involved with timing. Both loops are running independently. There is no way to guarantee that one loop will write to the queue before the other loop reads the queue. So what is the difference if you are writing to a queue in one loop and reading the queue in another or if you are writing to a local in one loop and reading the local in another? Also, if you use queues, once you read the queue in the second loop, it is empty. You have to do special coding to retain the last value dequeued. With locals, there is always a value defined. I have attached an example of using locals with two parallel loops and I doubt that anyone can find anything wrong with this example.
I am not trying to encourage the use of locals everywhere, but they do have a use if used properly. Locals offer an easy exchange of data between parallel loops. If the programmer knows what he is doing, use them. Don't be scared to try them. I wish the experts here would stop scaring newcomers away from locals and globals like they are the plague. Instead, educate newcomers on how to avoid race conditions, and how to properly use locals and globals. Teach good programming, don't hide your head in the sand to avoid a potential problem. If newcomers are taught how to avoid the problems that may come with locals and globals, they will have become better programmers and will have more tools to work with.