03-29-2019 02:26 PM
I have a VI that is essentially parsing a text file into commanding Front Panel Objects. The reason for this is to iterate through various combinations.
Anyways-- I'm getting these two errors depending on slight changes to the attached VI.
Error 1: occured at dequeue element. (invalid character)
Error 1122: occured at dequeue element (invalid refnum).
What is causing this error?
Also-- how do I synchronize my state machines so that the three loops essentially correspond to one line of text in sample_error.txt?
Anything else I can do to my VI to make it more seamless?
There are a few VIs in the attached folder. The one I'm talking about is queue_data_error.
Solved! Go to Solution.
03-29-2019 09:57 PM
I can explain the 1122 Error -- never let the Producer release the Queue! I recently wrote an "essay" in response to another poster asking about Producer-Consumer -- find the Post this week with "LabVIEW - How to stop Producer Loop" as the Title. Read my long post just before the Post that was marked as the Solution -- it will explain "safe" management of Producer/Consumer Designs.
Bob Schor
04-01-2019 07:21 AM
I believe it was my earlier post that you had commented on. I had to change a few things to post my VI. I read your comment on that post of producer/consumer tips. However, I'm still not following what you mean by not letting the producer release the queue. My program has the "release queue" function outside of the producer loop.
When I didn't have the "Stop Producer Loop" case structure in my program, it never exited the while loop even after the array from my fileread.vi has been passed.
04-01-2019 07:57 AM
@sam18 wrote:
However, I'm still not following what you mean by not letting the producer release the queue. My program has the "release queue" function outside of the producer loop.
When the Producer releases the Queue, the Consumer cannot use it! So the Producer does (or doesn't) put something on the Queue, and then kills the Queue without knowing the state of the Consumer. Meanwhile, the Consumer may be waiting for the next Element (or may still be processing, and will loop to start waiting), and the Queue is not there! Oops.
The idea of a Sentinel is that (a) the Producer "knows" when it can stop Producing, (b) the Producer can send a signal (the "Sentinel") to the Consumer by putting an "End-of-Queue" element (an empty array, a blank String, something unique) on the Queue, and then simply exit, leaving the Queue alone. The Consumer, when it dequeues, checks for the Sentinel. If it is not present (the usual case), it just "consumes" normally. If it is present, it knows that the Producer has exited, that no more will be coming, so it is safe to exit. With both Producer and Consumer having exited, it is also safe for the Consumer to Release the Queue.
Didn't I say that earlier clearly enough?
Bob Schor
04-01-2019 08:15 AM
I like to think of a Queue as a box of chocolates.
Wheny ou buy a box of chocolates (As Forrest Gump has noted) you never quite know what you're going to get, but you can take the chocolates out one by one (Dequeue). The box (The Queue itself), however was produced at a factory.
Imaging the surprise of allowing the factory to dispose of the box at any time, independent of whether you, the consumer, has finished with it or not. Hmm, halfway through a dinner party and you want to pass around the cocolates and -poof- the box (along with it's contents) is gone. Not nice. OR imagine the producer going out of business before you can finish your chocolates.... again -poof- chocolates are gone.
Of course the correct way to do this is for the producer to pass ownership of the box to you (the consumer) so that when you decide you are finished with it (when all chocolates are finished or you start that new diet) you can dispose of it. The box and the producer have independent lifetimes.
04-01-2019 08:21 AM
I understand the problem on a conceptual level. It's on the implementation level that I'm not entirely sure. Where in my code am I ending the producer before the consumer can process the elements?
04-01-2019 08:28 AM
@sam18 wrote:
I understand the problem on a conceptual level. It's on the implementation level that I'm not entirely sure. Where in my code am I ending the producer before the consumer can process the elements?
You close the queue when you exit the producer loop. There is no guarantee that the consumer loop will be finished with the queue when you close it. You should close the queue when you exit the consumer loop.
04-01-2019 08:31 AM
Ohh I see--so i shouldn't have the case structure within my producer loop. Thanks. Will fix that.
04-01-2019 09:41 AM
That would be good idea, but that won't fix the problem. You need to move your close queue from the exit of the producer to the exit of the consumer.