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
0 answers

How to synchronize a queue shared from consumer/producer thread in python 3.5

I have synchronization problem creating the producer/consumer problem with semaphore in python 3.5. In particular when I acquire the producer semaphore, simultaneously (I think this is the problem, but I'm not sure and if so I don't know why) the…
0
votes
1 answer

print garbage values from the shared memory

I am currently working on a producer-consumer implementation using C. First, I create a buffer on the shared memory of a variable length that is given by the user in the consumer process. Then, in the producer process, I need to access the shared…
0
votes
0 answers

Java Producer-Consumer, trap to sleep after first cycle

There are simple producer / consumer functions in java. Problem is after only one cycle, both get into the sleep trap and doesn't get awake. The issue is notify from consumer doesn't reach to producer to make it awake. In my case the consumer should…
A. Fasih
  • 73
  • 1
  • 10
0
votes
1 answer

activemq consumer does not return data even when queue not empty

I wrote a sample code to add elements to activemq, and then retrieve them. I was successfully able to add around 1000 elements, but while retrieving the elements, somehow code gets stuck after retrieving around 50 - 200 elements, even when the queue…
vishva
  • 366
  • 5
  • 17
0
votes
1 answer

Java synchronized queue thread on producer and consumer

Java producer-consumer program using thread & synchronized queue, the program is separated into 3 classes but it couldn't be run. Queue.java: public class Queue { static final int MAXQUEUE = 3; int[] queue = new int[MAXQUEUE]; int front,…
0
votes
1 answer

producer consumer model like scenario is not working

This is the scenario. I have to poll a ftp server in a timed interval and get the csv files. Then these CSV files has to be parsed and send as a input to some business logic. I have done it in this way. FTPClientPolling (Producer) public class…
RamValli
  • 4,389
  • 2
  • 33
  • 45
0
votes
1 answer

Consumer causing memory leak on Wildfly AS

I have a producer consumer setup using a Wildfly AS for JMS, the producer uses a newFixedThreadPool(126) every 1 minute each thread is pulling data down from a REST service and is pushing it onto a HornetQon the Wildfly AS. Then on the consumer side…
JTK
  • 1,469
  • 2
  • 22
  • 39
0
votes
2 answers

Infinite loop multi-threading

I have written this Producer/Consumer Problem solution. It seems to be working, other than the infinite loop. I was under the impression that pthread_exit(NULL); would make it stop, but honestly, I've become lost and confused. Could someone point me…
0
votes
1 answer

An approach to multithreaded file processing

I have a quite large file(> 15 GB)(never mind what kind of file). I have to read file, do some processing with data, then write processed data to a blank file. I do it in chunks. Each chunk contains a header of some sort, followed by the data. The…
isxaker
  • 8,446
  • 12
  • 60
  • 87
0
votes
0 answers

Consumers stop recieving messages from RabbitMQ broker while connections and channels are still open

I've seen similar issues on other threads but none with conclusive answers. I'll spin up around 4 consumers (written in Ruby using the Bunny client gem) to subscribe to the same queue and process the messages and all works fine until about…
0
votes
2 answers

C++ - Producer / Consumer only allow consumption in defined chunks

There's two threads A (Producer) and B (Consumer). The data A produces is only meant to be read in chunks, hence B shall only be allowed to read once A has produced a whole chunk. A single piece of data is a simple struct and the chunk length is…
keyboard
  • 2,137
  • 1
  • 20
  • 32
0
votes
0 answers

Why does my producer-consumer blocks?

That's simple (almost)solution to producer-consumer problem. It uses wait and signal functions, but probably blocks on one of the waits. Here are my files: prod.c int *pam; #define MAX 10 #define MAX2 12 #define PUSTY 2 //EMPTY #define S1 0 #define…
xukay
  • 1
  • 1
0
votes
2 answers

Multiple Producer consumer in java

My code works well when there is one producer and one consumer. But if i have more than one consumer or producer they got the same value.(I have seen many answers but they are complicated is there any simple solution). class QC { int n; boolean…
Shuvo
  • 29
  • 1
  • 5
0
votes
1 answer

Throttle/block async http request

I have a number of producer tasks that push data into a BlockingCollection, lets call it requestQueue. I also have a consumer task that pops requests from the requestQueue, and forwards async http requests to a remote web service. I need to throttle…
Alexander Pope
  • 1,134
  • 1
  • 12
  • 22
0
votes
1 answer

Thread Producer-Consumer java

i have to finish an exercise where i have to go find ".java" files in my folder path using the producer/consumer pattern with at least one producer thread and x consumer threads. ProducerConsumer-class: First i tried to stop the consumer when the…
Timo N.
  • 341
  • 3
  • 12