LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does setting Dequeue Element Timeout to a value other than -1 = Polling?

Hi All,

 

Trying to understand some under-the-hood operation of the Dequeue Element function. I know the default is wait forever (-1) , this should make the queue event based. So just like my topic title, if I set timeout to a number other than -1, does that mean it becomes polling based?

 

Thanks,

Mike

0 Kudos
Message 1 of 10
(3,370 Views)

No. If it times out, there is no new value on the queue and you are not polling it. OTOH, the timeout allows other things in the same loop to be polled (e.g. stop button ,etc.). 

 

Still it is typically more efficient to keep the timeout at -1 and do polling operations in their own loop. Make sure you fully understand dataflow principles.

Message 2 of 10
(3,364 Views)

So, what, besides the timeout Boolean = TRUE, happens on a timeout?  Does it return default data type value(s) or does it return the last known value(s)?  It sure seems like polling if you have a timeout.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 10
(3,354 Views)

Yes, the question is itself a bit weird, because we first need to define what polling really means. Let's start reading here.

 

Instead of worrying about semantics, we should just define what the needs are and what functionality we should implement. Even if the timeout is infinite, you are "polling it" (by some definition of the term), it just won't answer until something gets put on the queue elsewhere and thus stall the loop until that happens. The "time" element is an important part of it. It is still polling if you set the timeout to  24 hours?

 

All that said, I don't want to put labels on something. You can call it anything you want as long as you know what it actually does. 😄

 

It seems rather pointless to spin a loop and poll a queue with a short timeout unless there is other code in the same loop that should run repeatedly and does not depend on the queue value.

 

 

0 Kudos
Message 4 of 10
(3,341 Views)

It returns default data. With user defined data types, this may be used to manage the timeout condition without checking the timeout? boolean output.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 5 of 10
(3,336 Views)

The dequeue function itself does not turn into a polling mode or something with TO !=0.

 

Queues use very low level mechanisms, that go all the way down to OS and CPU provided functionality.

 

However, if TO is not -1, you will have to poll the queue in your code, if you want to continuously read values.

 

If TO = 0, the function will simply check if there's an element.

 

If TO= -1, the function will wait (on OS level) until there's an element, or until the event is cancelled.

 

If TO>0, the function will wait for the OS level event, with a TO.

0 Kudos
Message 6 of 10
(3,331 Views)

@altenbach wrote:

Yes, the question is itself a bit weird, because we first need to define what polling really means.


Well, is just waiting for a queue element technically polling?  I would say no because it is relying on an interrupt, which greatly reduces CPU time.

 

Of course, I feel that I have to through this out for those using RT and FPGA.  If you use an RT FIFO or a DMA FIFO on the host side, the read will actually poll for data.  They will use 100% of a CPU core while waiting for data to come in.  This is done for determinism since polling can react faster than interrupts.

 

So after thinking about this a little more, I would say that using a timeout for the queue is a form of polling.  But is that really bad?  I don't think so.  Sometimes you need to do something in the loop periodically in the loop with the Dequeue Element.  I do this commonly in my Queued Message Handlers where the controller will send a command to start a process and later another command to stop.  In the middle, I use the timeout of the queue so I can see if a new message came in and still keep doing whatever it is the loop is supposed to do.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 10
(3,300 Views)

wiebe@CARYA wrote:

The dequeue function itself does not turn into a polling mode or something with TO !=0.

 

Queues use very low level mechanisms, that go all the way down to OS and CPU provided functionality.

 

However, if TO is not -1, you will have to poll the queue in your code, if you want to continuously read values.

 

If TO = 0, the function will simply check if there's an element.

 

If TO= -1, the function will wait (on OS level) until there's an element, or until the event is cancelled.

 

If TO>0, the function will wait for the OS level event, with a TO.


That's what I meant by "polling".  I guess I got mixed up about just exaclty what was doing the polling.  No wonder that I confused Alt.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 10
(3,293 Views)

@crossrulz wrote:

@altenbach wrote:

Yes, the question is itself a bit weird, because we first need to define what polling really means.


Well, is just waiting for a queue element technically polling?  I would say no because it is relying on an interrupt, which greatly reduces CPU time.

 

Of course, I feel that I have to through this out for those using RT and FPGA.  If you use an RT FIFO or a DMA FIFO on the host side, the read will actually poll for data.  They will use 100% of a CPU core while waiting for data to come in.  This is done for determinism since polling can react faster than interrupts.

 

So after thinking about this a little more, I would say that using a timeout for the queue is a form of polling.  But is that really bad?  I don't think so.  Sometimes you need to do something in the loop periodically in the loop with the Dequeue Element.  I do this commonly in my Queued Message Handlers where the controller will send a command to start a process and later another command to stop.  In the middle, I use the timeout of the queue so I can see if a new message came in and still keep doing whatever it is the loop is supposed to do.


Yes, I knew I remembered someone who used this to their advantage, and I guess it's you.  I've long thought about using this technique but I haven't had a chance to use it yet.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 10
(3,288 Views)

@crossrulz wrote:

@altenbach wrote:

Yes, the question is itself a bit weird, because we first need to define what polling really means.


Well, is just waiting for a queue element technically polling?  I would say no because it is relying on an interrupt, which greatly reduces CPU time.

 

Of course, I feel that I have to through this out for those using RT and FPGA.  If you use an RT FIFO or a DMA FIFO on the host side, the read will actually poll for data.  They will use 100% of a CPU core while waiting for data to come in.  This is done for determinism since polling can react faster than interrupts.

 

So after thinking about this a little more, I would say that using a timeout for the queue is a form of polling.  But is that really bad?  I don't think so.  Sometimes you need to do something in the loop periodically in the loop with the Dequeue Element.  I do this commonly in my Queued Message Handlers where the controller will send a command to start a process and later another command to stop.  In the middle, I use the timeout of the queue so I can see if a new message came in and still keep doing whatever it is the loop is supposed to do.


 

I guess my clarification to what altenbach is asking for definition of polling is more inline with what crossrulz is stating, I was guessing timeout = -1 to be an event or interrupt based.

 

On the flip side, if timeout != -1, I would have guessed it would have been a more efficient version of "polling" with "Get Queue Status" to see if there is data to dequeue before timeout occurs. From some of the answers in here, this doesn't seem like the case and seems to me that even with a timeout != -1, the dequeue function is still highly efficient.

0 Kudos
Message 10 of 10
(3,246 Views)