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
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
335 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 ...
1
vote
1answer
288 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
3k 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
778 views

Producer-Consumer in C++ - follow-up

To expand from the changes supplied by the answer of my previous question: ...
4
votes
1answer
1k 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 ...
6
votes
2answers
5k views

Producer-Consumer in C++

This is my first experimentation with the producer-consumer problem (and thread manipulation in general), so any feedback on taboos and fixes is greatly appreciated! ...
1
vote
1answer
900 views

Thread pool implementation in Java

I am studying multi-threading and have tried to implement a thread pool. Please provide feedback, mostly from multi-threading point of view. I have implemented two pools, one for adding tasks in queue ...
3
votes
1answer
2k views

Implementing a JMS consumer

I need a standalone client that consumes messages from the queue every time a message exists. I already have set-up an ActiveMQ queue named hello.world. ...
11
votes
1answer
16k views

One producer multiple consumers

I want to code the following scenario: One Producer: produces n (n=100 here) objects m Consumers (m = 5 here): consumes k (k = 10 here) objects at a time in a round robin fashion; Consumer 1 first ...
2
votes
1answer
1k views

Message queue with multiple producer, single consumer and no duplicates

I had to make a message queue in an android app which my thread takes messages from and processes them. There can be multiple producers and duplicate messages should be avoided. Rate of insertion is ...
0
votes
1answer
1k views

Event-based producer/consumer in C#

I want to create a production-ready producer/consumer that could help me avoid thread synchronization hell. Is this thread-safe? The main issue is to be safe with exceptions that can arrive. ...
3
votes
1answer
552 views

Simple wrapper to use IEnumerable as a producer in a producer-consumer pattern

I have a relatively simple problem: I have an IEnumerable<T>, which takes considerable time to yield each term. This is then used by another piece of code, ...
2
votes
0answers
94 views

Porting Java semaphore to MacOSX

I wanted to write some more JNI code and decided to (re)implement a semaphore for MacOSX. In order to assert somehow correctness of my implementation I hereby supply a (multi)consumer/(multi)producer ...
5
votes
2answers
697 views

Producer consumer water cooler example

I have written a water cooler example in which the consumer drinks from the water cooler until it's empty and when it gets empty the producer fills it up. The consumers wait until it's filled up and ...
5
votes
0answers
2k views

Disruptor pattern in a lock-free producer-consumer queue

I'm implementing a quick-and-dirty lock-free MPMC queue in C++, based on the v3 Disruptor algorithm. The implementation is pretty simple: Data to be shared between threads is stored in a ring buffer. ...
28
votes
2answers
57k views

A multi-threaded Producer Consumer with C++11

I am trying to learn concurrent programming in C++11. I tried to write code for a classic producer consumer concurrency problem. Would you please review and make any comments about it? ...
2
votes
1answer
4k views

Readers-Writers problem in C

I would love some suggestions on this code of mine, pointers on overall design, code quality, optimization in terms of memory and speed. ...
3
votes
3answers
995 views

Producer-consumer code

The idea I have in my head is this: I am not sure if I need the index variable in consumer and producer. Moreover, I want to know if it is OK like this (it seems ...
17
votes
3answers
4k views

Producer/Consumer programs

I am studying mutual exclusion in college, and we just covered the producer/consumer problem. The class does not involve writing code, but I decided to implement a bounded buffer version of this ...
5
votes
1answer
349 views

Lockless, blocking, non synchronized multiple producers and consumers ring buffer

My program is structured like this: there are M producer threads, each of which computes a section of an object O with index <...
2
votes
1answer
525 views

Producer - Consumer interaction

I have an implementation of Producer-Consumer multi-threaded interaction. It works, but I feel that during the execution wait states happen too often between ...
2
votes
1answer
279 views

Controller for a MUD client

I want to ensure that, as much as possible given my skill level, that I'm using relevant patterns correctly and following naming conventions. This is a controller for a poor-mans MUD client using ...
6
votes
1answer
1k views

1 producer, n consumer with QThread

I am new to C++ and to threading, so I'm sorry if my code is bad. I'm here to get it better and to learn. Any kind of advice (both on C++ style, on Qt usage, or on threading handling) is welcome. ...
15
votes
1answer
5k views

Lock-free multiple-consumer multiple-producer queue

The code below implements an intrusive lock-free queue that supports multiple concurrent producers and consumers. Some features: Producers and consumers work on separate ends of the queue most of ...
2
votes
1answer
1k views

Producer/Consumer with some limitations

The code realizes producer/consumer problem with multiple producers and consumers. Have this code any potential deadlock or races? ...
1
vote
2answers
4k views

Multithreading concepts with Producer Consumer

I just wanted to confirm if this example I created would qualify as a good example of a multithreaded producer consumer. I would like any review changes on improving this example. I found that static ...
2
votes
1answer
5k views

Boost Threads - Producer Consumer threads with synchronization

Please review this for concurrency correctness: ...
2
votes
2answers
1k views

boost::thread producer consumer

I am new toboost::thread and am making a producer-consumer with a Monitor. This is how I've coded it so far: ...
6
votes
2answers
6k views

Producer / Consumer implementation for Parallel Processing in the TPL

I've stripped this down to its bare bones removing stopping/cancellation logic etc... to keep it simple. The Producer is a very simple class containing a timer. At ...

1 2