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

MQTT in Producer /consumer context

we are using ActiveMQ for message Queuing with openwire transport.In this context there will be one producer and one consumer with a message listener registered. We heard about MQTT protocol and its support in activeMQ. But i saw examples only for…
Tom Sebastian
  • 3,373
  • 5
  • 29
  • 54
0
votes
2 answers

Safe way to ensure not missing cond signal

Is this a safe way to ensure that the master thread will never miss a wake up signal if no other thread uses the variable flag? void *Cancel_master_thread(void *arg) { while (1) { flag = 0; pthread_mutex_lock(&cancel_in_progress); …
iiirxs
  • 4,493
  • 2
  • 20
  • 35
0
votes
1 answer

Do you need to call shmat and shmget in both producer and consumer files?

In the producer process, I have the following. say MEMKEY is key_t 234500, and *shared_ring is a pointer to the data structure (donut_ring) that is being shared. int shmid, semid[3]; if((shmid = shmget (MEMKEY, sizeof(struct donut_ring), …
Iancovici
  • 5,574
  • 7
  • 39
  • 57
0
votes
0 answers

Disruptor, Synchronization Mechanism

Do disruptor queues provide superior performance when there are N Producers and 1 consumer? I wrote a program with Multiple Producer and Single Consumer using Disruptor Queues. I find the results are neck-on-neck with blocking arraybounded queues.…
0
votes
2 answers

Stop sending messages to broker

In my scenario I have one boroker, one producer, one consumer.I am using activemq for writing my app. logs to db.As u know writing logs to db is time taking process.That's why consumer is more and more slow than producer.For ex. I send 100.000…
0
votes
1 answer

How to push messages from Activemq to consumer

I am new to Activemq and Java,I read tutorials,somewhat I understand.can anyone help me to solve the following task. Imagine we have a 10 messages in Queue/Topic of Activemq. we are getting messages from Database,we already did it. I want to write 2…
Hanumath
  • 1,117
  • 9
  • 23
  • 41
0
votes
1 answer

Apache Kafka - Consumer not receiving messages from producer

I would appreciate your help on this. I am building a Apache Kafka consumer to subscribe to another already running Kafka. Now, my problem is that when my producer pushes message to server...my consumer does not receive them .. and I get the below…
ASingh
  • 475
  • 1
  • 13
  • 24
0
votes
1 answer

How to consume messages selectively from Spring AMQP?

In the queue I have pushed 10K objects. Timestamp is one of the attribute in object. So, how can I write a consumer code using spring amqp? can anyone help me on this.
Pand005
  • 1,095
  • 3
  • 23
  • 53
0
votes
1 answer

NSOperation or GCD threading with animations

I'm trying to run a sequence of disk-based, old-school AVI animations (A then B then C...), back-to-back, with a nice transition in between. I'm looking for a little guidance admittedly not having done threading work for some time, and certainly…
zzyzy
  • 973
  • 6
  • 21
0
votes
3 answers

Why my producer consumer program is blocking?

I have created my own queue . Queue.java public class MyQueue { private int size; private Queue q; public MyQueue(int size ,Queue queue) { this.size = size; this.q = queue; } //getter and setter …
Thinker
  • 6,820
  • 9
  • 27
  • 54
0
votes
3 answers

LinkedBlockingQueue.take() seems to be busy all the time

I'm trying to implement a service in OSGi which should wait for incoming data from another bundle and process the data when it receives it. I'm using a LinkedBlockingQueue, because I don't know how many packets I will receive. My code looks like…
PieterDB
  • 285
  • 4
  • 14
0
votes
2 answers

Python inter-process Queue overflow

I have a producer set-up with N consumers. The producer listens on a socket which receives a high volume of TCP messages (10,000 per min), reads this data and puts it into the Queue for the workers. The workers I have set-up to read from the Queue…
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
0
votes
3 answers

Why consumer is not consumin data in this program

I'm new to java and I'm trying to implement simple producer consumer problem. Below is the code that i've written to test it. I have 3 classes, Main class, producer class and consumer class. Now the problem is my producer is producing the data but…
0
votes
1 answer

Is it possible to dispatch no more than N number of messages from the queue at a given time with distributed consumers?

I have a distributed system that reads messages from RabbitMQ. In my situation now I need to process no more than N msgs/s. For example: Imagine service A that sends text messages (SMS). This service can only handle 100 msgs/s. My system has…
Vor
  • 33,215
  • 43
  • 135
  • 193
0
votes
3 answers

ActiveMQ some consumers not picking up tasks if they arrive after producer

Im just getting starting with ActiveMQ and i seem to have a weird problem. (Source below) There are 2 scenarios Consumers connect to broker, waits for tasks on the queue. Producer arrives later, drops the list of tasks and they are rightly taken…
Shrayas
  • 6,784
  • 11
  • 37
  • 54