AlexA Posted February 10, 2010 Report Share Posted February 10, 2010 Hey everyone I'm reaching the end of my tether with these while loops running in parallel. My program seems to run fine but then when I hit the stop button it just hangs and doesn't exit. Can someone tell me, or link me to an explanation of how to propagate a stop condition in producer consumer loops, in addition, how should I destroy the queues so that they are destroyed in the right order? My code is attached if it's of any help at all. Regards and thanks for your time. Alex Quote Link to comment
Mark Balla Posted February 10, 2010 Report Share Posted February 10, 2010 Hey everyone I'm reaching the end of my tether with these while loops running in parallel. My program seems to run fine but then when I hit the stop button it just hangs and doesn't exit. Can someone tell me, or link me to an explanation of how to propagate a stop condition in producer consumer loops, in addition, how should I destroy the queues so that they are destroyed in the right order? My code is attached if it's of any help at all. Regards and thanks for your time. Alex The problem is the timeout input on your dequeue node is set to -1 which means it will wait forever until there is an element to dequeue. One of the primary rules of data flow is any structure (in this case a while loop) must wait until all items are complete before it can continue. In your program the loop is waiting for the dequeue node to complete and the node is waiting for an element to be put in the queue. The node will also release if the queue reference is destroyed. So one solution would be to set the stop buttons and then destroy all of the queues. This should release the dequeue node and let the while loop continue. Closing the queue reference will also produce an error out of the dequeue node and many programmers wire the error out to the stop terminal of the while loop. The Producer/Consumer Design Pattern (Data) uses this method. Hope this helps Mark 1 Quote Link to comment
AlexA Posted February 10, 2010 Author Report Share Posted February 10, 2010 Hey Mark Thanks for your solution, I had a little trouble implementing it initially because I didn't put in the case structure, i.e. if no error -> do code, otherwise -> do nothing. As an aside, how much does having the error checking case slow the code down in your experience? Is an error signal a logic 1 or 0? If so I can't imagine it slowing things down too much, if it's a package containing error information with every check that might slow things down. Your thoughts? I ask because speed is crucial in the application I'm trying to create. Kind Regards Alex Quote Link to comment
AlexA Posted February 10, 2010 Author Report Share Posted February 10, 2010 And another quick question about queues, if I tell something to enqueue as fast as possible (0 timeout) and my dequeing code can't possibly keep up, what happens to the data? Is it destroyed or lost somehow? Or does the code behave like a lossy enqueue rather than a normal one? Regards Alex Quote Link to comment
Mark Balla Posted February 10, 2010 Report Share Posted February 10, 2010 Hey Mark Thanks for your solution, I had a little trouble implementing it initially because I didn't put in the case structure, i.e. if no error -> do code, otherwise -> do nothing. As an aside, how much does having the error checking case slow the code down in your experience? Is an error signal a logic 1 or 0? If so I can't imagine it slowing things down too much, if it's a package containing error information with every check that might slow things down. Your thoughts? I ask because speed is crucial in the application I'm trying to create. Kind Regards Alex Looking at your posted code the error checking case structure is insignificant compared to the other nodes. I doubt you could even measure the difference. And another quick question about queues, if I tell something to enqueue as fast as possible (0 timeout) and my dequeing code can't possibly keep up, what happens to the data? Is it destroyed or lost somehow? Or does the code behave like a lossy enqueue rather than a normal one? Regards Alex The obtain queue node has a max queue size input. If this is set to -1 the queue can be as big as your RAM will allow. The data in the queue will only be lost if you release the queue before you dequeue all the items. If you input a non negative number to the max size then you have two options. If you use the normal enqueue and the queue is full the node will wait until it has timed out and then discard the input element. If you use the lossy enqueue the node will push out the oldest element. two queues.vi Quote Link to comment
smenjoulet Posted February 10, 2010 Report Share Posted February 10, 2010 And another quick question about queues, if I tell something to enqueue as fast as possible (0 timeout) and my dequeing code can't possibly keep up, what happens to the data? Is it destroyed or lost somehow? Or does the code behave like a lossy enqueue rather than a normal one? Regards Alex You don't need to specify a 0 timeout if you want to enqueue something as fast as possible. If there is room in the queue, it will be put on it. If you are using an unbounded queue, then theoretically the function will happily enqueue items until you run out of memory no matter what timeout value you specify. If you have a bounded queue (as in your example) and it is full, then the enqueue function will wait until the timeout expires or space becomes available. If the timeout happens first, no enqueue takes place. You will not get an error from the function, but you can check the 'timeout' output to see if a timeout occurred. -Scott Quote Link to comment
AlexA Posted February 11, 2010 Author Report Share Posted February 11, 2010 Hey guys Yeah I reached the conclusion that a 0 timeout on the enqueue is just gonna result in data not getting enqueued at all for that loop iteration, what I was wondering is what happens to that data? Regards Alex Quote Link to comment
Mark Balla Posted February 11, 2010 Report Share Posted February 11, 2010 Hey guys Yeah I reached the conclusion that a 0 timeout on the enqueue is just gonna result in data not getting enqueued at all for that loop iteration, what I was wondering is what happens to that data? Regards Alex To clarify the timeout is the amount of time the enqueue will wait for a spot to become open in the queue. For queues that have no size limit it's value has no meaning. a timeout of 0 simply means the node will not wait if the queue is full and will discard the input element. Mark Quote Link to comment
Mark Yedinak Posted February 12, 2010 Report Share Posted February 12, 2010 To clarify the timeout is the amount of time the enqueue will wait for a spot to become open in the queue. For queues that have no size limit it's value has no meaning. a timeout of 0 simply means the node will not wait if the queue is full and will discard the input element. Mark I haven't played with the lossy queues but what does the timeout do in that case. Will it wait that long before it queues the data and discards the oldest entry? Alex, I would recommend that you use an event structure for capturing your user events. By doing so you will not have to poll the values of the control and your code will be more efficient because your UI task (loop) will be doing nothing unless an event is detected. In a polling model it is constantly doing something and chewing up CPU cycles. (Of course if you only have the base version of LabVIEW you are stuck since NI does not provide the event structure in the base package. Something they really should do.) Quote Link to comment
Mark Balla Posted February 14, 2010 Report Share Posted February 14, 2010 I haven't played with the lossy queues but what does the timeout do in that case. Will it wait that long before it queues the data and discards the oldest entry? The Lossy enqueue has no timeout input. Quote Link to comment
AlexA Posted February 15, 2010 Author Report Share Posted February 15, 2010 Mark, as regards an event structure. Do you believe that it will make a significant difference given that the limiting factor on my code is the tone search algorithm?? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.