FAQ Database Discussion Community


Observing changes in a BlockingCollection without consuming

c#,multithreading,concurrency,producer-consumer,blockingcollection
A consumer thread and multiple producer threads synchronize their work with a System.Collections.Concurrent.BlockingCollection<T>. The producers call blockingCollection.Add() and the consumer runs foreach (var item in blockingCollection.GetConsumingEnumerable()) {...} Now one producer wants to "flush" the buffer: The producer wants to wait until all current items have been consumed. Other producers may...

An implementation of integer buffer that creates deadlock

multithreading,graph,buffer,deadlock,producer-consumer
Let’s consider the following pseudocode: class OneBuf{ Mutex m; CondVar cv; int buffer; bool full; void put(int data){ m.lock(); while(full){ cv.wait(m); } buffer = data; full = true; cv.signal(); m.unlock(); } int get(){ int data; m.lock(); while(!full){ cv.wait(m); } full = false; data = buffer; cv.signal(); m.unlock(); return data; }...

Linux pthread Producers and Consumers

c,multithreading,concurrency,pthreads,producer-consumer
I have to write a POSIX threads and semaphores based implementation of Producers and Consumers Problem for academical purposes. To check if the implementation is valid I sum all the 'goods' which are produced and all which are consumed. The problem is that second sums vary between subsequent executions of...

Data type for a “closable” queue to handle a stream of items for multiple producers and consumers

python,multithreading,queue,producer-consumer
Is there a specific type of Queue that is "closable", and is suitable for when there are multiple producers, consumers, and the data comes from a stream (so its not known when it will end)? I've been unable to find a queue that implements this sort of behavior, or a...

Producer Consumer Separate Classes with common BlockingCollection

c#,.net,vb.net,producer-consumer,blockingcollection
Hoping someone can give some advice regarding the Producer/Consumer Pattern – in particular on how best to achieve a Queue/BlockingCollection which is COMMON to all producers/consumer class instances? Lets Simplify the scenario; Consider I have; A single Producer class A single single Consumer class. A Service Class which contains instances...

Blocking Queue - Why is there no notify()

java,multithreading,client-server,producer-consumer
I was going through this bounding queue code online trying to understand it public class BlockingQueue { private List queue = new LinkedList(); private int limit = 10; public BlockingQueue(int limit){ this.limit = limit; } public synchronized void enqueue(Object item) throws InterruptedException { while(this.queue.size() == this.limit) { wait(); } if(this.queue.size()...

Remove cancelled Task from producer/consumer queue

c#,async-await,producer-consumer
I want to use an async producer/consumer queue (AsyncEx lib) to send messages one at a time over a bus. Right now I achieve this simply by async blocking. It's working fine, but I have no control over the queue :( So I came up with following solution, problem is...

For producer-consumer pattern which implementation is better : ArrayBlockingQueue or Arraylists with Exchangers

java,concurrency,producer-consumer
Usecase : its a producer consumer pattern where order (FIFO) is to be maintained. As of now there is single producer and a single consumer to process data in sequential manner to maintain order, but in future ( due to removal of some business constraint ) this requirement of maintaining...

Producer consumer not giving desired result

java,multithreading,synchronization,producer-consumer
I'm learning thread synchronization from java documentation. I implemented a famous problem Producer-consumer problem. But it is not giving result as expected. I've searched a lot about this problem at HERE, HERE, HERE, HERE, HERE and some other stack-exchange and non-stack exchange sites but unable to resolve my problem. Here...

rabbitmq(pika) throws an exception when use RPC

python,rabbitmq,rpc,producer-consumer,pika
RabbiMQ RPC throws an exception when i build publisher-consumer pattern. This is my code: sender.py # coding:utf-8 import pika import uuid class MessageSender(object): def __init__(self): self.connention = pika.BlockingConnection( pika.ConnectionParameters(host='localhost')) self.channel = self.connention.channel() result = self.channel.queue_declare(exclusive=True) self.callback_queue = result.method.queue print 'MessageSender callback queue is ------', self.callback_queue self.channel.basic_consume( self.on_response, no_ack=True,...

Should I implement the consumer/producer pattern in my java video app, and if yes, how?

java,multithreading,producer-consumer
I built a small video frame analysis app with desktop Java 8. On each frame, I extract data (5 doubles now, but could expand to a 1920x1080x3 OpenCV Mat in the future). I would like to store this data into a database (Java DB, for example) to perform some time-series...

Notify Waiters at Thread Exit

c++,c++11,boost,boost-thread,producer-consumer
Consider the following example. Suppose you have one producer and N consumers waiting for data. You want to notify the consumers not only whenever the data is ready but also when the producer terminates for some reason (an error, or an interruption point). In the latter case, the readers should...

Moving data from one BlockingCollection to the other

task,c#-5.0,producer-consumer
I have a code, that copies integers to buffer1, then from buffer1 to buffer2 and then consumes all data from buffer2. It processes 1000 values in 15 seconds, which is a lot of time compared to size of input. When I remove the " Task.Delay(1).Wait() " from the second task...

pthread_mutex_wait multiple producer and consumer

c++,multithreading,pthreads,posix,producer-consumer
I was going through this and this link. Basically, they are discussing why classical single threaded producer consumer design (with signal and wait does not work for multi-producer scenario). I have one doubt which has been bugging me - Argument made by author Consider reference code char queue[MAX]; //global int...

Best way to sequentially pass list values to single value consumer?

java,java-8,producer-consumer,completable-future
I'm toying with Java8's streams and CompletableFutures. My pre-existing code has a class that takes a single URL and downloads it: public class FileDownloader implements Runnable { private URL target; public FileDownloader(String target) { this.target = new URL(target); } public void run() { /* do it */ } } Now,...

producer / hybrid consumer in C# using 4.0 framework classes and Blocking Collection

c#,multithreading,c#-4.0,concurrency,producer-consumer
I have a situation in which I have a producer/consumer scenario. The producer never stops, which means that even if there is a time where there are no items in the BC, further items can be added later. Moving from .NET Framework 3.5 to 4.0, I decided to use a...

Audio stream for multiple outputs (single producer, multi-consumer)

c#,naudio,producer-consumer
I am attempting to propagate a single sound source to multiple outputs (such as one microphone input to multiple sound cards or channels). The output does not have to be sync'd (a few ms delay is acceptable) but it would be nice if it could be sync'd. I have successfully...