The behavior you are talking about doesn't always occur with the Producer/Consumer design pattern, since the communication between the loops can take various forms. The default implementation for the design pattern seen in the LabVIEW templates and online help, however, will have the effect you are mentioning. Here's why and what you can do if this really is a problem for you:
The LabVIEW templates implement the P-C design pattern such that the Consumer loop is automatically shut down when the Queue gets destroyed. It does this by wiring the error terminal from the Dequeue Element function into the terminal condition input of the while loop. When the Queue gets destroyed following the producer loop, this causes the Dequeue Element function to error out which shuts down the loop. This is why (most likely) your Consumer loop runs once more than the Producer Loop. If the Producer Loop sends N messages, the Consumer Loop must run N times to handle these messages, then it must run once more to wait for the Release Queue function.
This shouldn't ever be a problem. You might also notice another thing the templates do is wire the Error Out from the Dequeue Element function in the Consumer Loop into a case structure, and then only use the dequeued element value if there isn't an error (if the Queue hasn't been destroyed). So you shouldn't have to worry about actually processing dummy default data if you follow this guideline.
Now, if it will still be a problem to operate in this manner, then you will have to build the shutdown command from the Producer loop into your communication mechanism. For instance, you could send a cluster with a boolean and your data to the Consumer Loop. A true boolean value means this is the last iteration, and the consumer loop should shut down after processing the data. There's a million ways to accomplish this, but as I said, it probably isn't necessary to even bother.
Message Edited by Jarrod S. on 01-15-2007 10:29 AM
Jarrod S.
National Instruments