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

Does RabbitMQ keeps an open connection for the consumer?

I am trying to implement a RabbitMQ solution in an environment where all connections have to be started from the secure zone to the less secure zone. The standard RabbitMQ implementation foresees the use of consumer subscription and callbacks. I…
0
votes
1 answer

Mutex blocking the thread in a producer-consumer problem

I have a fundamental question regarding the producer consumer problem. Please consider the below pseudo-code. // Consumer. This is in the thread I created for asynchronous log writing // so that I don't block the important threads with my…
user8244274
0
votes
1 answer

Kafka Consumer not reading messages

I have Kafka v1.0.1 running on the single node and I am able to push the messages to the topic but somehow unable to consume the message from another node using the below python code. from kafka import KafkaConsumer consumer = KafkaConsumer( …
0
votes
0 answers

Producer consumer pattern with buffer priorities OCL

I want to modelate the producer consumer problem, with an infinite buffer that recive generate data from productor, and stores them by a priority level: High, Medium, Low. Then, the consumer extract them and process then,asking only for one per…
jff
  • 300
  • 3
  • 14
0
votes
1 answer

Will notify interrupt the sleeping thread?

I have implemented Classical example of producer and consumer. Here producer will sleep for 10 seconds after producing value = 0 [will not go waiting for the state because of queue size is one which is less than 10 ]. And the consumer will consume…
Neelabh Singh
  • 2,600
  • 12
  • 51
  • 88
0
votes
1 answer

why does producer consumer queue with single producer/consumer doesn't need mutex?

The code From wikipedia for producer consumer queue with a single producer and a single consumer is: semaphore fillCount = 0; // items produced semaphore emptyCount = BUFFER_SIZE; // remaining space procedure producer() { while (true) { …
Gulzar
  • 23,452
  • 27
  • 113
  • 201
0
votes
3 answers

Simple producer-consumer collection without BlockingCollection

I want to write a simple producer-consumer queue, without using the built-in System.Collections.Concurrent.BlockingCollection. Here's a quick attempt that "seems" to work. Is there anything wrong with it threading-wise, race conditions, deadlocks…
kaalus
  • 4,475
  • 3
  • 29
  • 39
0
votes
1 answer

Solve: Lock-Free Queue Multiple-Producer Multiple-Consumer - Memory Corruption

The LockFreeQueueMPMC should solve the MPMC problem without locks, but during the runtime there is memory corruption. LockFreeDispatchStackMPMC does solve the MPMC problem without locks and is used as a basis for the LockFreeCacheMPMC allocator.…
0
votes
2 answers

Kafka Consumer receiving same message

I am new to Kafka and I have a Kafka consumer implemented using Java Apache Camel library. The issue I found out is - Consumer takes a long time(>15 mins) to process for few messages- which is fine for our use case. Need some config help because the…
Xavier DSouza
  • 2,861
  • 7
  • 29
  • 40
0
votes
2 answers

How is the producer and consumer problem solved by using java's monitor?

I have a thread subclass which represents arrivals at a public office and a thread subclass which represents the caseworkers. Every time a person is arrived, the person's name is entered. There are 2 entrances for the office where the arrivals can…
user3740970
  • 389
  • 1
  • 3
  • 16
0
votes
1 answer

Mechanism for reading all messages from a queue in one request

I need a solution for the following scenario which is similar to a queue: I want to write messages to a queue continuously. My message is very big, containing a lot of data so I do want to make as few requests as possible. So my queue will contain a…
0
votes
1 answer

How to wait and retrieve the result in producer-consumer pattern?

I have an application which uses producer-consumer pattern: multiple producers, one consumer. The catch here is that inside each producer, after submitting the task, I want to wait and retrieve the result inside the same producer process: from…
0
votes
1 answer

How to use multiple producers and one consumer with activeMQ?

So i am trying to use ActiveMQ within my java project (I never used anything like this before but I've read about how it works). The application runs on 5 different nodes and on each of them are created the messages that should be send into the same…
Georgiana_M
  • 47
  • 1
  • 7
0
votes
1 answer

Producer consumer problem display a wrong order

Following producer consumer code displays a wrong order(before producer produce consumer consumes. sometimes producer produce many items(cubbyhole allows one item only)). why is that? public class CubbyHole { private int content; private…
0
votes
1 answer

How to implement fairness in Task Executor consuming tasks from Blocking queue

I would like to implement a consumer service which is processing tasks from a queue. The consumer service / task runner I have implemented using an executor service. However some of the tasks I need to process take longer than others and I would…
Mojo
  • 1
  • 3