The Queue module is primarily used to manage to process large amounts of data on multiple threads. It supports the creation of a new queue object that can take a distinct number of items.
The
get() and
put() methods are used to add or remove items from a queue respectively. Below is the list of operations that are used to manage Queue:
- get(): It is used to add an item to a queue.
- put(): It is used to remove an item from a queue.
- qsize(): It is used to find the number of items in a queue.
- empty(): It returns a boolean value depending upon whether the queue is empty or not.
- full(): It returns a boolean value depending upon whether the queue is full or not.
A
Priority Queue is an extension of the queue with the following properties:
- An element with high priority is dequeued before an element with low priority.
- If two elements have the same priority, they are served according to their order in the queue.
Below is a code example explaining the process of creating multi-threaded priority queue:
Example:
Output:
initializing Thread-1
initializing Thread-2initializing Thread-3
Thread-2 processing AThread-3 processing B
Thread-3 processing C
Thread-3 processing D
Thread-2 processing E
Exiting Thread-2
Exiting Thread-1
Exiting Thread-3
Exit Main Thread
Note: The output may differ depending upon the device specifications and processing power.