08-16-2013 11:10 AM
I have a queue that is consistently updated with values from an FPGA via a telnet connection.
Right now I have a loop that polls the queue constantly and processes anything that's in it. I was thinking a better design practice would be to have an event structure that processes queue elements in it anytime there is something in the queue (as opposed to polling).
However, I'm not sure how to accomplish this. Right now the only thing I can think of is to have a variable that stores the queue size and run the event structure based on a change in the value of that variable. But this defeats the purpose cause I think I'd have to poll the queue constantly to determine it's size.
On the other hand, values are arriving constantly in the queue, so maybe polling it is the best way.
Thoughts?
08-16-2013 11:14 AM - edited 08-16-2013 11:15 AM
Hi,
the "dequeue" function has a timeout parameter. Wire -1 or nothing, and your program will do nothing as long as no new data arrives in your queue
08-16-2013 11:17 AM
Oh ok...so I guess I use this in conjunction with the timed out? output??
In other words - wire nothing to the timout in ms input, then wire the timed out? output to a case structure that executes when timed out? == FALSE
correct?
08-16-2013 11:35 AM
@bmishoe wrote:
I have a queue that is consistently updated with values from an FPGA via a telnet connection.
Right now I have a loop that polls the queue constantly and processes anything that's in it. I was thinking a better design practice would be to have an event structure that processes queue elements in it anytime there is something in the queue (as opposed to polling).
However, I'm not sure how to accomplish this. Right now the only thing I can think of is to have a variable that stores the queue size and run the event structure based on a change in the value of that variable. But this defeats the purpose cause I think I'd have to poll the queue constantly to determine it's size.
On the other hand, values are arriving constantly in the queue, so maybe polling it is the best way.
Thoughts?
I don't understand about "polling" the queue. Without a timeout, the dequeue will just sit around and wait for something to be put in the queue. It doesn't "poll." You shouldn't need an event structure - or anything else, for that matter - to keep it from "polling."
08-16-2013 11:40 AM
Allow me to clarify...I inherited this code from someone else. There's a while loop set up with a timer, and on each iteration it dequeues an element and then processes it. This code runs every 10 ms. So if nothing's in the queue then obviously nothing happens...but I was looking for a way to get rid of the while loop.
So right now, it's hierarchically (sp?) like this:
while loop->dequeue->case structure
So you're saying I can get rid of the while loop and the dequeue will execute of its own accord (if I don't have a timeout hooked up) whenever an element arrives, right?
08-16-2013
11:43 AM
- last edited on
05-14-2025
09:46 PM
by
Content Cleaner
@bmishoe wrote:
Oh ok...so I guess I use this in conjunction with the timed out? output??
In other words - wire nothing to the timout in ms input, then wire the timed out? output to a case structure that executes when timed out? == FALSE
correct?
No, you don't have to do anything. It will just sit there until something gets put in the queue. You probably need to go and brush up on dataflow programming.
08-16-2013
02:11 PM
- last edited on
05-14-2025
09:46 PM
by
Content Cleaner
I suggest reading up on the Producer/Consumer architecture. If you don't wire the timeout (ms) input, then the dequeue will wait for data to enter the queue. You can then process the data the was dequeued. You will need a while loop to repeat the "wait for data and process incoming data".
Maybe it would help your cause if you posted the code so we can get a little better context.