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.

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. The producer's job is to generate a piece of data, put it into the buffer and start again. At the same time the consumer is consuming the data (i.e., removing it from the buffer) one piece at a time. The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer.

The solution for the producer is to either go to sleep or discard data if the buffer is full. The next time the consumer removes an item from the buffer, it notifies the producer who starts to fill the buffer again. In the same way, the consumer can go to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping consumer. The solution can be reached by means of inter-process communication, typically using semaphores. An inadequate solution could result in a deadlock where both processes are waiting to be awakened. The problem can also be generalized to have multiple producers and consumers.

References

1564 questions
0
votes
1 answer

c# Producer/Consumer Queue releasing

I read producer/consumer queue implementation Producer/Consumer Queue. It works great, but i'm worrying if client forgets to call Shutdown(). How should i implement releasing of working threads? Thanks.
FCBshnik
  • 103
  • 1
  • 2
  • 8
0
votes
2 answers

Issue with Producer Consumer in Java - Missing synchronization?

I guess I have not used synchronization properly. I get the below output . I have consciously chosen not to use BlockingQueue OR java 5 concurrency features. I had written this so that I could learn synchronization and some basics. Producer Thread:…
serah
  • 2,057
  • 7
  • 36
  • 56
0
votes
1 answer

Consumer not consuming messages when created dynamically

I am learning to implement active mq interface in my project. This is how I am creating producers and consumers. public void connectionSetup(String portName) { // portname is object of PortTO class. We are creating producer and consumer pair for…
user746458
  • 369
  • 2
  • 13
  • 26
0
votes
1 answer

Mitigate effects of polling ring buffers

I have a single producer multiple consumer program with threads for each role. I am thinking of implementing a circular buffer for tcp on each of the consumers and allow the producer to keep pointers to the circular buffers' memory then handing out…
BAR
  • 15,909
  • 27
  • 97
  • 185
0
votes
1 answer

Producer/consumer seems to be in deadlock when buffer is smaller than input from producer

I made a circular buffer with multiple clients writing (in the end I want them to write messages of different size) into a buffer. The server reads them out. It's based on the code in a consumer/producer problem: #include #include…
Thomas
  • 1,678
  • 4
  • 24
  • 47
0
votes
2 answers

How LMAX's Disruptor work with Multiple producer with a shared variable?

I am new to Disruptor. I have the following two queries: Q1. I got a sample code of one producer to one consumer and one producer to multiple dependent consumers, I like to get a sample code for multiple producers to multiple consumers or a…
0
votes
1 answer

Lua producer-consumer pattern with consumers waiting for different data

The problem One data source generating data in format {key, value} Multiple receivers each waiting for different key Example Getting data is run in loop. Sometimes I will want to get next value labelled with key by using Value =…
Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
0
votes
1 answer

JMS Producer-Consumer-Observer (PCO)

In JMS there are Queues and Topics. As I understand it so far queues are best used for producer/consumer scenarios, where as topics can be used for publish/subscribe. However in my scenario I need a way to combine both approaches and create a…
lanoxx
  • 12,249
  • 13
  • 87
  • 142
0
votes
1 answer

Producer/Consumer threads do not give results

I'm doing a CPU scheduling simulator project for my OS course. The program should consist of two threads: producer and consumer threads. The producer thread includes the generator that generates processes in the system and the long term scheduler…
0
votes
3 answers

producer/consumer using boost threads and circular buffer hangs

I figured it out. Silly mistake on my part, I was not actually deleting the element from the queue, I was just reading the first element. I modified the code and the code below no works. Thanks all for the help. I'm trying to implement the producer…
shaun
  • 560
  • 1
  • 11
  • 29
-1
votes
3 answers

Are there any other queues in the standard library?

I want to queue lambda : Popen(.....) To call/wait at a later time. Then add some more to paused Popens to the queue, then consume them again and so on. The main Queue module cares a lot about synchronization and this makes the api feel a bit…
Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
-1
votes
1 answer

Restrict the number of time an application is installed on machine

How does a big key product like those of MSOffices restrict their buyers/users by either the number of its installation times or the number of its installed machines ? For one software CD, the product are installed and useable via for example 3…
Sesama Sesame
  • 279
  • 3
  • 6
  • 19
-1
votes
1 answer

Extremely strange behavior of the tasks in multithreaded environment

I am losing my mind. Look at this code using a concurrent queue: private readonly ConcurrentQueue _queue; private bool _isSaveActivated = false; public void Save(T model) { _queue.Enqueue(model); Debug.WriteLine("Enqueue " +…
T.S.
  • 18,195
  • 11
  • 58
  • 78
-1
votes
1 answer

Consumer Producer Queue .get() Loading Forever

I have a list of URLs in article_urls: list[str] and I'm trying to create several workers which go to the URLs and get a different URL from the webpage and then put that URL in another queue. I want several other workers to go through that other…
-1
votes
1 answer

kafka + This server is not the leader for that topic-partition

I have 5 broker kafka version 0.10 cluster.Replication factor is 3. and this is production kafka brokers IDS are 101 102 103 104 105 after couple months that cluster was ok , we observed following logs in Kakfa server.log. from the log we can see…
Judy
  • 1,595
  • 6
  • 19
  • 41
1 2 3
99
100