What Is a Queue?

Updated Nov 8, 2018

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full

Issue Details

It has been suggested to me that I should use a queue in my code. What is a queue and how do I use it?

Solution

A queue maintains a first in/first out (FIFO) order of data items. For instance, the customers waiting in line at a fast food restaurant are in a queue. The first customer to arrive is going to be the first one served.

A queue is useful in producer/consumer situations, where one portion of code is creating data to be used by another portion. The advantage of using a queue is that the producer and consumer rates do not have to be identical. If consumption is slower than production, the queue will eventually become full and the producer code will be forced to wait until the consumer has dequeued an element before a new element can be queued up.

Additional Information

Unlike an array, it is not possible to randomly access elements in a queue.  It is strictly a buffer that provides you the ability to enqueue (add/insert) and dequeue (subtract/remove) elements.  The only way to view all the elements in a queue is to dequeue them one by one.  You cannot perform data manipulation to all the elements in a queue either.

Look for example programs in the LabVIEW shipping examples. Open the LabVIEW Example Finder by selecting Help » Find Examples and then search for Queue in the search tab.

For information on other types of data transfer, see Data Communication Methods in LabVIEW.

WAS THIS ARTICLE HELPFUL?

Not Helpful