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.

Filter by
Sorted by
Tagged with
2
votes
1answer
38 views

Producer-Consumer Semaphore Implementation

I have implemented a Producer-Consumer by Semaphore implementation. I am looking forward to for your code review comments. Thanks. ...
3
votes
1answer
259 views

C++20 sort of infinite “Consumer-Producer”

I think I can summarize the idea to the Producer-Consumer problem, with some modifications. And I think i misused the term "Producer" (it depends from which point of view :)) An infinite ...
4
votes
1answer
72 views

One consumer and two producers using threads

I have based this code on Producer-Consumer Threading on Real Python. The idea is that I have 2 producers: One producer will give result every 0.4 to 0.7 seconds, depending on REST call. The second ...
2
votes
0answers
47 views

Managing exceptions in aiohttp using consumer-producer pattern

I implemented a simple producer-consumer where producer produces links to fetch and several workers consume those URLs and return write data into response queue. Unfortunately, sometimes API can start ...
1
vote
1answer
147 views

A multi-thread Producer Consumer, where a Consumer has multiple Producers (C++17) - Part 2

This post is based on A multi-thread Producer Consumer, where a Consumer has multiple Producers (C++17). I am trying to build a Consumer that consumes data from ...
5
votes
3answers
1k views

A multi-thread Producer Consumer, where a Consumer has multiple Producers (C++17)

EDID: Thank you very much for your feedback. I updated the code and opened a new post for the updated version. See here. This post is loosely based on A multi-threaded Producer Consumer with C++11. ...
2
votes
1answer
1k views

Simple Producer-consumer implementation in Python

I implemented a simple solution to the Producer–consumer problem that I'd love for you to take a look at. The producer simply adds random numbers to a queue and the consumer (from a separate thread) ...
3
votes
1answer
168 views

Producer consumer with threads and using boost ring buffer

I have two threads, one is the producer and other is consumer. My consumer is always late (due to some costly function call, simulated in below code using sleeps) so I have used ring buffer as I can ...
4
votes
0answers
132 views

Java multithreading many readers one writer implementations

I have a shared data object with writer threads and reader threads. Number of threads can read from the shared data at the same time (in the code getmethod), and ...
1
vote
0answers
429 views

First readers-writers problem using a single condition

For the first readers-writers problem, in which readers can access a given resource simultaneously, is the following Python3 solution correct? Problem parameters: One set of data is shared among a ...
9
votes
3answers
2k views

C++ lock free, single producer, single consumer queue

Assumptions for use: push() will only ever be called by a single thread. pop() will only ever be called by a single thread. Requirements: push() needs to be as fast as possible. Requirements are ...
2
votes
0answers
718 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
459 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
290 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
303 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
534 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
1k 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
540 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.) ...
7
votes
1answer
2k 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
994 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 ...
12
votes
0answers
1k 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
309 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
491 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
3k views

A simple implementation of the producer/consumer pattern

Consider this class that consumes some items and handles them with the provided handler function: ...
5
votes
1answer
853 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 ...
7
votes
1answer
1k 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
2k 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
932 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
881 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
622 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
2k 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
748 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
260 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: ...
2
votes
0answers
583 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 ...
6
votes
1answer
3k 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 ...
2
votes
3answers
220 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
3k 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
134 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
599 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
704 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
885 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
4k 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. <...
2
votes
0answers
134 views

Producer Consumer With Multiple Dependents [closed]

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
438 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
951 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
2k 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
439 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
490 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 ...