Questions tagged [queue]

A queue is an ordered, first-in-first-out data structure. Typical implementations of queues support pushing elements to the back and popping them off the front position.

  • A queue is not limited to a fixed capacity
    • A bounded queue is a queue limited to a fixed number of items
  • A doubly linked list is a good implementation choice

Operations

  • enqueue - pushes an element to the end of the queue
  • dequeue - pops an element from the front of the queue

See Also

Resources

Queue Wikipedia Article

11098 questions
36
votes
3 answers

Equivalent of asyncio.Queues with worker "threads"

I'm trying to figure out how to port a threaded program to use asyncio. I have a lot of code which synchronizes around a few standard library Queues, basically like this: import queue, random, threading, time q = queue.Queue() def produce(): …
Seth
  • 45,033
  • 10
  • 85
  • 120
36
votes
10 answers

Implementation of a work stealing queue in C/C++?

I'm looking for a proper implementation of a work stealing queue in C/CPP. I've looked around Google but haven't found anything useful. Perhaps someone is familiar with a good open-source implementation? (I prefer not to implement the pseudo-code…
unknown
35
votes
4 answers

Use concurrent.futures with new tasks for a real-time scenario

It is fairly easy to do parallel work with Python 3's concurrent.futures module as shown below. with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: future_to = {executor.submit(do_work, input, 60): input for input in…
Ali Gajani
  • 14,762
  • 12
  • 59
  • 100
35
votes
2 answers

Can I use a multiprocessing Queue in a function called by Pool.imap?

I'm using python 2.7, and trying to run some CPU heavy tasks in their own processes. I would like to be able to send messages back to the parent process to keep it informed of the current status of the process. The multiprocessing Queue seems…
Olson
  • 1,884
  • 2
  • 17
  • 18
35
votes
3 answers

Immutable queue in Clojure

What is the best way to obtain a simple, efficient immutable queue data type in Clojure? It only needs two operations, enqueue and dequeue with the usual semantics. I considered lists and vectors of course, but I understand that they have…
mikera
  • 105,238
  • 25
  • 256
  • 415
35
votes
5 answers

How to get the items in Queue without removing the items?

get() removes and returns an item from Queue in Python. import queue q = queue.Queue() # Here q.put("Apple") q.put("Orange") q.put("Banana") print(q.get()) print(q.get()) print(q.get()) Output: Apple Orange Banana Now, I want to get the items…
damon
  • 8,127
  • 17
  • 69
  • 114
35
votes
1 answer

Python Queue get()/task_done() issue

My consumer side of the queue: m = queue.get() queue.task_done() Questions: Does task_done() effectively pops m off the queue and release whatever locks the consumer has on the queue? I need to use m during the rest of the…
bandana
  • 3,422
  • 6
  • 26
  • 30
35
votes
4 answers

How to clone object in C++ ? Or Is there another solution?

I wrote a Stack and Queue implementation (Linked List based). There is one stack (bigStack). For example, I separate bigStack (example: stackA and stackB). I pop() a node from bigStack, I push() in stackA. In the same way, I push() in stackB. I want…
mert
  • 920
  • 3
  • 15
  • 24
35
votes
4 answers

Why is there no generic synchronized queue in .NET?

I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but the same method isn't available on Queue. Does anyone know why? Seems kind of weird.
skb
  • 30,624
  • 33
  • 94
  • 146
35
votes
3 answers

Why can't I construct a queue/stack with brace-enclosed initializer lists? (C++11)

Program 1: #include #include #include int main(){ //compiles successfully std::vector vec{1,2,3,4,5}; return EXIT_SUCCESS; } Program 2: #include #include #include…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
34
votes
2 answers

python queue & multiprocessing queue: how they behave?

This sample code works (I can write something in the file): from multiprocessing import Process, Queue queue = Queue() def _printer(self, queue): queue.put("hello world!!") def _cmdDisp(self, queue): f = file("Cmd.log", "w") print >>…
DrFalk3n
  • 4,926
  • 6
  • 31
  • 34
34
votes
3 answers

Executing tasks in parallel in python

I am using python 2.7, I have some code that looks like this: task1() task2() task3() dependent1() task4() task5() task6() dependent2() dependent3() The only dependencies here are as follows: dependent1 needs to wait for tasks1-3, dependent2…
Mohamed Khamis
  • 7,731
  • 10
  • 38
  • 58
34
votes
8 answers

Does the iOS SDK provide queues and stacks?

I'm writing an iPhone app, and I'm surprised that there seem to be no NSQueue or NSStack classes in Apple's Foundation Framework. I see that it would be quite easy to roll my own, starting with an NSMutableArray, so I'll do that unless I've missed…
Tommy Herbert
  • 20,407
  • 14
  • 52
  • 57
34
votes
5 answers

How to clear a multiprocessing.Queue?

I just want to know how to clear a multiprocessing.Queue like a queue.Queue in Python: >>> import queue >>> queue.Queue().clear() Traceback (most recent call last): File "", line 1, in AttributeError: 'Queue' object has no…
FelipeG
  • 445
  • 2
  • 5
  • 6
34
votes
10 answers

How can I animate multiple elements sequentially using jQuery?

I thought it would be simple but I still can't get it to work. By clicking one button, I want several animations to happen - one after the other - but now all the animations are happening at once. Here's my code - can someone please tell me where…
lnvrt
  • 732
  • 3
  • 11
  • 23