Defining a Queue
- A queue is used for threaded programming
-
There are three types of queues:
- A FIFO queue
- A LIFO queue
- A priority queue
- A priority queue ensures entries are kept sorted
- Specifically, the lowest-valued entry is retrieved first
- Internally, these queues use locks to temporarily block competing threads
-
Specifically, the
get()
andput()
functions are thread-safe- Or, these functions are free of race conditions
- However, they are still exposed to experiencing deadlocks
Differentiating between Queue
and deque
Queue.Queue
andcollections.deque
serve different purposesQueue.Queue
is used for communicating between threadscollections.queue
is used as a data structure only- In other words, a queue should be used for multithreaded programming
- A deque can be used for singlethreaded programming
References
Previous
Next