Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [producer-consumer]

The Producer-Consumer Problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue.

2
votes
0answers
79 views

C++ Producer / Consumer multi threads pattern with maximum container size

I've just written a Producer / Consumer pattern templatized that should work in multi threads environment (IE producer(s) and consumer(s) in separate threads). The original use case is one producer ...
2
votes
0answers
65 views

Many-readers-one-writer with semaphores and multithreading

I've been looking for a solution to the may readers one writer in Java. I was intrigued by this question posted here and I read the Wikipedia entry about it. So far, I've reached a fine solution, or ...
2
votes
1answer
104 views

Producer consumer design and implementation using Java 8

Please review my design and code implementation and suggest if any optimisation is possible in terms of performance (time complexity / space complexity ) or any better way of design or implementation. ...
1
vote
1answer
126 views

Infinite producer using BlockingCollection [closed]

Please have a review of this Code chunk and let me know whether it is a good way for infinite Producer? ...
3
votes
2answers
288 views

Customized lock-free RingBuffer

I have implemented my own lock-free ringbuffer for multiple producers multiple consumers using vector. Can you guys help me review to see if there are any problems and ways to improve? Explanation: ...
6
votes
1answer
324 views

Generic Producer-Consumer in C++11

I wrote the following simple 1 producer - 1 consumer problem, in attempt to learn some C++11 threading / generics. ...
0
votes
1answer
235 views

Lock free consumer producer using memory barrier [closed]

I am looking for "complete" producer-consumer sample using C++11 memory barrier. (I have derived following example from Jeff's article and added a line to make it complete.) ...
6
votes
1answer
971 views

Multiple-producer, single-consumer lock-free circular queue

I'm working on a firmware on a bare-metal ARM single core processor (Cortex M4), with no RTOS. I need to add a multiple-producer, single-consumer, lockless fixed-size circular (ring) buffer to the ...
4
votes
1answer
323 views

Processing a file using Producer/Consumer Model

I am trying to write a multi-threading program which implements the Producer/Consumer model. Typically, I want to use one Producer which reads lines from a file and ...
10
votes
0answers
581 views

Realtime concurrent Haskell MIDI buffer

Problem Background MIDI is a serial representation of control signals to a sound generator. Typically, a noteOn message initiates the attack phase of a sound at a given pitch. The note will ...
5
votes
2answers
306 views

Collaboration of the two functions through multithreading

I'm going to turn them (multi-threading) to the first function after the end of the operation to notify the second function that has already finished work and the second function it received through ...
2
votes
0answers
385 views

Producer Consumer Using TPL Dataflow

I have written the following class which is supposed to act as a consumer of messages that are passed in from producers and forward them onto amazon SQS, I have made a compromise by starting the ...
1
vote
1answer
2k views

A simple implementation of the producer/consumer pattern

Consider this class that consumes some items and handles them with the provided handler function: ...
4
votes
1answer
642 views

Non blocking single producer/consumer queue with C++11 atomics

I've recently got interested in lockless programming, mainly lockless queues for job repartitions, so here I undertook a challenge of creating lockless queue for single producer and consumer. This is ...
8
votes
1answer
630 views

Buffered queue for logging

I'd like to use a buffered queue for logging via a WebAPI that handles multiple applications. This helper should reduce the blocking that occures due to logging. I've been experimenting with a ...
5
votes
2answers
1k views

Bounded Queue with multiple consumers and multiple producers

It was an interview question: Should implement a class - BlockingQueue with those constraints: 2 Methods - Adding an item and Take an item from the queue. The class should support multiple consumers ...
1
vote
0answers
640 views

Load balancing consumer and producer with multiprocessing

Tasks are distributed to producer in multiple worker process. Results from workers are sent through Queue to a ...
7
votes
1answer
565 views

Optimizing producer consumer using monitors

I am trying to review concurrency concepts, i.e monitor, semaphores, etc. I've learned that Semaphores are natively not available in C++11 (presumably because it is very error prone) - which is why I ...
4
votes
3answers
486 views

Producer-Consumer with Peterson algorithm in java

Producer-consumer problem in Java with a circular buffer of N positions. There is a single thread representing the producer that will produce consecutive integer elements There is a dimensioned ...
1
vote
3answers
1k views

Notifying consumers when a producer is done

I am writing a simple program with a producer and a few consumers: the producer pushes to a queue some integers, and the consumers pop elements from the queue and print them (order doesn't matter). ...
3
votes
1answer
531 views

Producer - multiple consumer implementation using futures

I've tried to implement a producer-multiple consumer pattern using futures and I was wondering should it ever deadlock, and if it should, why? I have this method ...
3
votes
0answers
215 views

Optimal Implementation Choice for Producer-Consumer in Java

I am looking for an optimal producer-consumer implementation in Java with the following aspects: Producer reads from server1 socket, and writes to a shared buffer, as well as another server 2 socket: ...
1
vote
0answers
485 views

Producer / consumer pattern with limits on .NET

For a project that I'm developing, I need to implement the producer/consumer pattern, but the quantity of consumers cannot be higher than some number (say 40). I created a concept project on GitHub ...
5
votes
1answer
2k views

Queue with multiple consumers and one producer

I've written a queue supporting one producer and multiple consumer threads. The idea is that the queue instances a definable number of long running consumer threads. Internally I'm using a ...
3
votes
3answers
190 views

Calculating average stock prices using producer/consumer with async

Task: calculate average price for each stock, using input data, which consists of stock id (int) and its price (float). It's important to detect jumps in prices, therefore need to keep correct ...
2
votes
2answers
2k views

Running multiple producer and single consumer in a multithread environment

I have a below class in which add method will be called by multiple threads to populate messageByChannelReference concurrent ...
5
votes
1answer
112 views

Concurrent stack in C - follow-up

This is a follow-up question to Concurrent stack in C The pop function not just removes the top element from the stack, but also returns it. If a pthreads call ...
7
votes
2answers
362 views

Concurrent stack in C

(See also the follow-up question.) I was in the mood for pthread.h and decided to write a concurrent stack data structure. My requirements: the stack has maximum ...
6
votes
1answer
475 views

Consumer/Producer (Concurrency) - Exception Handling

I have a circular buffer (array/first in first out), a consumer and a producer. A producer puts random numbers into the array, and a consumer takes the first number and checks if it is relative prime. ...
1
vote
2answers
580 views

One producer and multiple consumers wherein the producer has to wait until all consumers finish before adding more data

I am trying to solve the scenario involving 1 producer and 5 consumers. The producer puts data to queue and waits till all consumers have finished before adding more data. Please review and let me ...
5
votes
1answer
2k views

Consuming chunks from ConcurrentQueue

I need to implement a queue of requests which can be populated from multiple threads. When this queue becomes larger than 1000 completed requests, these requests should be stored into a database. <...
1
vote
0answers
124 views

Producer Consumer With Multiple Dependents

I put together a ProducerConsumer class that wraps the C#'s BlockingCollection class with some bells and whistles (producers can have multiple consumers, consumers can have lambdas, built in parallel ...
1
vote
2answers
1k views

Producer consumer in C++11

I'm trying to practice some C++ and I wrote a simple queue to solve the Producer-Consumer Problem. ...
2
votes
2answers
224 views

Relaying stdin data from one thread to another

I'd like to know if this piece of code is thread-safe. I'm learning something about threads, queues and synchronization, and I'd like to make sure this is correct, before moving forward to next step. ...
1
vote
1answer
577 views

Producer/Consumer implementation using condition_variable

Trying to implement producer/consumer problem in C++. I have one question: should I use nofify_all or notify_one method here? ...
0
votes
1answer
1k views

Multi Producer - Single Consumer

I have written multi producer single consumer code with bounded buffer. Please review the code for any improvements or mistakes. ...
1
vote
1answer
356 views

Multithreaded Producer-Consumer pattern

I have Producer Threads A, B and C producing 3 different types of events Events A, B and C respectively. The Consumer thread can ...
4
votes
3answers
315 views

Producer/consumer problem with four priority levels

Here you can see a mediocre code of mine where I have fun with four deques, each with a different priority. Here is how it works: in a ...
2
votes
1answer
2k views

Using BlockingCollection with Parallel.ForEach

I have a process that does a bunch of document processing. One of the tasks being performed is OCR, which is the slowest part of the process, so I decided to run that in another thread. I decided ...
2
votes
3answers
2k views

C++ fixed-size queue full/empty signaling

I'm considering an application where a large data needs to be written to file often. I would like to use a queue and have a producer and consumer running on different threads. Additionally, I would ...
3
votes
4answers
11k views

Reader-writers problem using semaphores in Java

I have written my own solution to the Reader-Writers problems using semaphores based on the psuedocode from Wikipedia. I would like to gauge the correctness and quality of the code. ...
7
votes
1answer
2k views

Producer Consumer in C

I'm doing multithreading at university and we've been asked to implement the producer consumer problem in C. My code compiles and produces the right result. From debugging it, it seems to be waiting ...
8
votes
1answer
2k views

Lock-free multi-producer multi-consumer queue

I'm looking for some feedback on my lock-free queue, based on Disruptor, mainly for any potential concurrency issues, such as where I need additional fences. It looks correct to me, and I can't seem ...
4
votes
0answers
313 views

Producer-consumer with a twist (consumer is a reader) in C++

Executive summary The twist is that the consumers do not consume, they just read. The producer makes items continuously in one of two alternating slots. Readers read from the other slot. When ...
0
votes
1answer
245 views

Multiple producers accessing multiple shared queues by checking for space two times

I request a review on the way multiple producers and consumers access multiple shared queues. What I have done here requires the threads to check for the space in queues minimum two times. Can it be ...
2
votes
2answers
2k views

Producer/consumer implementation using Tasks and BlockingCollections

I'm implementing a Producer/Consumer but the generic interface doesn't require any knowledge of blocking collections or tasks. ...
6
votes
1answer
2k views

Simulation of Multiple Producer Consumer

I am trying to implement the Multiple Producer-Consumer problem. I have made the buffer as the lock to maintain consistency of the system. Does this system actually implement multithreading? How can I ...
5
votes
1answer
2k views

Producer Consumer using custom blocking queue

After the feedback I have got from this question, I tried to to re-implement the classic Producer Consumer problem using multithreading. The requirements are: If the queue is not full, all the ...
2
votes
1answer
636 views

Producer-Consumer in C++ - follow-up

To expand from the changes supplied by the answer of my previous question: ...
4
votes
1answer
963 views

Rewriting to single pipeline by using data flow blocks

I have a number of messages with a payload as a list of items. My goal is to transform the message payload without losing the relation between the message and payloads. Isn't it possible to rewrite ...