Questions tagged [concurrent-queue]

Concurrent Queue is thread-safe first in - first out (FIFO) collection.

Concurrent Queue is thread-safe first in - first out (FIFO) collection/container.

Implementations

93 questions
32
votes
3 answers

Try Dequeue in ConcurrentQueue

The TryDequeue in ConcurrentQueue will return false if no items in queue. If the queue is empty I need that my queue will wait until new item to be added in queue and it dequeue that new one, and the process will continues like that. Should I use…
C-va
  • 2,910
  • 4
  • 27
  • 42
22
votes
2 answers

Is it safe to put TryDequeue in a while loop?

I have not used concurrent queue before. Is it OK to use TryDequeue as below, in a while loop? Could this not get stuck forever? var cq = new ConcurrentQueue(); cq.Enqueue("test"); string retValue; while(!cq.TryDequeue(out retValue)) { …
ManInMoon
  • 6,795
  • 15
  • 70
  • 133
15
votes
3 answers

How to create no-duplicates ConcurrentQueue?

I need a concurrent collection that doesn't allow duplicates (to use in BlockingCollection as Producer/Consumer). I don't need strict order of elements. From another hand i want to minimize the maximum time of element "live" in collection. I.e.…
Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305
6
votes
3 answers

How to multithread queue processing

C++ containers are supposed to be thread-safe by default. I must be using queue to multithread incorrectly because for this code: #include using std::thread; #include using std::cout; using std::endl; #include using…
Chris Redford
  • 16,982
  • 21
  • 89
  • 109
6
votes
0 answers

Using Concurrency::concurrent_queue together with std::unique_ptr

I want to use the Concurrency library of Visual Studio 2010 to pass actions between threads. I have my class SimpleAction and pointers to it are stored in the Concurrency::concurrent_queue. Using this definition, and 'consumption' logic it…
Patrick
  • 23,217
  • 12
  • 67
  • 130
5
votes
1 answer

ConcurrentQueue .Net: Multithreaded consumer

I had a very basic question which is more around concepts of ConcurrentQueue. A queue is FIFO. When multiple threads start accessing it, how do we guarantee FIFO? Suppose, I have added Apple, Oranges, Lemon, Peach and Apricot - in that order. The…
Kallol
  • 264
  • 1
  • 12
4
votes
1 answer

What is the difference between TryDequeue and TryTake in a ConcurrentQueue<>?

In the ConcurrentQeueue<> class, and extra method TryDequeue() is defined. But, as it implements IProducerConsumerCollection<>, it also has a TryTake() method. According to the docs, they both do the same thing: TryDequeue: Tries to remove and…
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
4
votes
1 answer

Why can't complexity of ConcurrentLinkedQueue.size() be constant?

Javadoc for ConcurrentLinkedQueue explicitly states that the complexity of the size() method is O(n). I find this surprising. I would follow the stock LinkedList.size() approach by accumulating the size in a counter. Given the asynchronous nature of…
4
votes
1 answer

Pattern to remove elements from ConcurrentQueue after peeking

I have one producer and multiple consumers. I am using ConcurrentQueue. I am using C# but I think my problem is language agnostics. There can be non-unique consumers. i.e. more than one consumers can be interested in same message. So, non-unique…
4
votes
2 answers

RxJS parallel queue with concurrent workers?

Let's say I want to I download 10,000 files. I can easily build a queue of those 10,000 files (happy to take advice if any of this can be done better), import request from 'request-promise-native'; import {from} from 'rxjs'; let reqs = []; for (…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
4
votes
1 answer

Worker Threads Blocking When ConcurrentQueue has too many items

This is a weird one, I have a Thread[] of worker threads which each process items in a ConcurrentQueue until the queue is empty, at which point the rest of the program continues. This works until about ~1500 items at which point all threads…
4
votes
5 answers

Why do ConcurrentQueue and ConcurrentDictionary have "Try" methods - TryAdd, TryDequeue - instead of Add and Dequeue?

ConcurrentQueue has TryDequeue method. Queue has just Dequeue method. In ConcurrentDictionary there is no Add method, but we have TryAdd instead. My question is: What is the diffrence between these concurrent collection methods? Why they are…
Kamil
  • 13,363
  • 24
  • 88
  • 183
4
votes
2 answers

ConcurrentQueue and Parallel.ForEach

I have a ConcurrentQueue with a list of URLs that I need to get the the source of. When using the Parallel.ForEach with the ConcurrentQueue object as the input parameter, the Pop method won't work nothing (Should return a string). I'm using Parallel…
Zroq
  • 8,002
  • 3
  • 26
  • 37
4
votes
1 answer

Example of TBB concurrent_queue use

The Intel Thread Building Blocks library includes a concurrent_queue container. Unfortunately, digging around on the internet has yet to yield an example of a concurrent_queue being used in a parallel manner by the TBB library. Could someone provide…
Richard
  • 56,349
  • 34
  • 180
  • 251
3
votes
2 answers

Why concurrent queue with sync act like serial queue?

Could anyone help me to understand this code I created: let cq = DispatchQueue(label: "downloadQueue", attributes: .concurrent) cq.sync { for i in 0..<10 { sleep(2) print(i) } } print("all finished!") And the output is serial order…
1
2 3 4 5 6 7