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

Is my design for sending data to clients at various intervals correct?

The code should be written in C++. I'm mentioning this just in case someone will suggest a solution that won't work efficient when implementing in C++. Objective: Producer that runs on thread t1 inserts images to Consumer that runs on thread t2. The…
theateist
  • 13,879
  • 17
  • 69
  • 109
0
votes
2 answers

Java: Producer/Consumer using BlockingQueue: having the consumer thread wait() until another object is queued

I've been having some thread related problems recently with a consumer that takes points. Here is the original, which works fine except for taking up a lot of cpu constantly checking the queue. The idea is that cuePoint can be called casually and…
0
votes
2 answers

Pact-js - Provider/Consumer test missing files in the repository

Hi everyone, I am trying to implement PACT JS. Currently I am referring to this implementation : npm install (or yarn install) and the consumer side command (mocha app/client/spec/PostServiceClient.spec.js) worked well.The pact file was…
0
votes
2 answers

Producer consumer collection with ability to read and write batches of data

I'm looking for a collection like BufferBlock but with methods like: SendAsync(T[]) T[] ReceiveAsync() Is anyone can help with?
0
votes
1 answer

Producer/consumer Pattern with dependency injection error

Java EE 7 - Injection into Runnable/Callable object Continuing this question, i have a situation... I'm using a Producer/Consumer pattern to consuming a list of objects. My Class Consumer is a implementation of Runnable. public class MYConsumer…
0
votes
0 answers

Deadlock scenario in Producer consumer pattern using Executor Service

In a producer consumer pattern using ExecutorService what if all threads starts executing the consumer task and blocks themselves waiting for the producer to push data indefinitely? Can this ever happen ?? If I have say X no of Url's to download…
debanka
  • 187
  • 1
  • 4
  • 13
0
votes
1 answer

producer/comsumer model and concurrent kernels

I'm writing a cuda program that can be interpreted as producer/consumer model. There are two kernels, one produces a data on the device memory, and the other kernel the produced data. The number of comsuming threads are set two a multiple of 32…
superscalar
  • 23
  • 1
  • 6
0
votes
2 answers

How to set message label using Weborb(Producer) and MSMQ

I`m adding a message in MSMQ by my flex program using this code: producer = new Producer(); producer.destination = "VendingMachineBack"; var m:AsyncMessage = new AsyncMessage("",{'MSMQLabel':"VS-GetSaleTypes"}) ; …
Arthur Neves
  • 11,840
  • 8
  • 60
  • 73
0
votes
0 answers

producer consumer threads synchronization

I was asked a question in HP interview. There is 1 buffer.There is 1 Producer thread and 2 consumer thread. How will you synchronize?My answer was struct Node { int data; Node * next; Node * lastPrev; }*buffer; sem_t…
Sandeep
  • 17
  • 1
  • 6
0
votes
2 answers

How to get consumer Kafka lag in java

I have a producer in java and consumer in nodeJS. I want to know in java what is the consumer lag, so i know if i can produce more data to the topic. What is the API in java to get the consumer lag?
0
votes
2 answers

Buffering of observable to stabilize variable delays for slower observer

I have one observable that produces a sequence of numbers with delays in between the numbers that range from 0 to 1 second (randomly): var random = new Random(); var randomDelaysObservable = Observable.Create(async observer => { var value…
Tom Pažourek
  • 9,582
  • 8
  • 66
  • 107
0
votes
1 answer

How to have dynamic number of producers and consumers?

There is a program which is implemented using producer and consumer pattern. The producer fetches data from db based on list of queries and puts it in array blocking queue... The consumer prepares excel report based on data in array blocking queue. …
0
votes
0 answers

Queue overwriting in multi producer multi consumer queue

In the following multi producer and single consumer fixed size queue implementation i see the queue being overwritten by producers. Why is the queue being overwritten? At this point am not looking at performance of the code but would like to see…
vishu
  • 71
  • 2
  • 7
0
votes
1 answer

read filter messages from Kafka topic according to consumer

How can we consume custom messages from multiple or a single partition in a Kafka topic? How can I read only 1 message when I consume messages from multiple partitions in a Kafka topic?
0
votes
2 answers

java assignment synchronization producer consumer

I've written a Multithreading code for producer consumer problem in which I've written synchronized block inside the run method of consumer and producer thread which takes lock on shared list(I assumed) So the point of question is that, will there…