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

C++11 memory_model_relaxed and memory_order_seq_cst relation

Hi I am trying to understand lock-free work stealing dequeue implementation. Currently, I am reading one implementation by google's filament here. I am mostly concerned about the steal operation. template TYPE…
kevinyu
  • 1,367
  • 10
  • 12
0
votes
0 answers

Producer-consumer problem about synchronization

I read the wikipedia about the Producer–consumer problem https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem It mentioned that in below code it works fine when there is only one producer and consumer. My question is that if producer is…
Howard
  • 143
  • 1
  • 1
  • 12
0
votes
1 answer

Consumer level message processing timeout in activemq

I Have a consumer subscribes to the queue using subscribe method with ack=client-individual mode. when an exception occurs it got hung up rather than processing the next message. In try block i have connection.ack() method and in catch block i just…
Kannan K
  • 77
  • 2
  • 12
0
votes
1 answer

How to process a kinesis stream record? (multiple processors)

I'm working on a project that monitors a micro-service based system. the mock micro-services I created produce data and upload it to Amazon Kinesis, now I use this code here from Amazon to produce to and consume from the Kinesis. But I have failed…
0
votes
1 answer

infinite loop in producer-consumer problem

I'm trying to gain a better understanding of fork() and concurrency in c programming. I'm a novice, and I'm having trouble understanding the logic. I tried to make a simple producer-consumer program using fork(). basically, a producer() function…
P. Gillich
  • 289
  • 1
  • 9
0
votes
1 answer

Why do consumers decrease the producer's performance

I'm currently trying to increase the performance of my software by implementing the producer-consumer pattern. In my particular case I have a producer that sequentially creates Rows and multiple consumers that perform some task for a given batch of…
0
votes
1 answer

How to Write Java multithreading Code for alternative producer and consumer approach. It should have 3 producers (P1,P2,P3) and 1 consumer(C1)

Can I Get a definite approach for achieving this. I have used join and wait for the alternative producer and consumer execution. This question was asked in an interview. He did not like my solution. I have also suggested a loop inside a synchronized…
0
votes
1 answer

Producer Consumer stuck in deadlock with consumer

I'm trying to implement the producer consumer with conditional variables so I can learn about synchronization. I'm using the github to guide me and solved some seg faults but now it seems that my consumer never gets executed or is stuck in deadlock.…
Nihal
  • 17
  • 1
  • 8
0
votes
1 answer

C++ Producer Consumer stuck in deadlock

I'm trying to create a producer-consumer program, where the consumers must keep running until all the producers are finished, then consume what's left in the queue (if there's anything left) and then end. You can check my code bellow, I think I know…
0
votes
1 answer

How does the kafka consumer of the same group share messages between them?

Say, there is a Consumer group. (Consumers with the same group ID). The Consumer group is consuming Topic A from a Broker. Topic A has 4 partitions, and there are 4 Consumers in that group. Each Consumer consumes different partition. ( Consumer 1…
Jin Lee
  • 3,194
  • 12
  • 46
  • 86
0
votes
2 answers

H2O producer java threads lock , reentrant lock

I want to produce h2o continuously by three threards first thread will produce h , second will produce h and third should produce o . How can I do it with lock ,consumer producer package com.threads.reentrantlock.consumerproducer; …
Ashish Banker
  • 2,243
  • 3
  • 20
  • 21
0
votes
1 answer

Synchronization error in consumer/producer style logger

I see lots of this sort of questions but none helped me so I post mine. I made a logger for multi-thread logging. Only one thread(Created when the very first logger is created.) deals with log messages from many threads and the buffer is…
0
votes
2 answers

Semaphore in Java. producer-consumer problem

I am testing the use of semaphores with the typical producer-consumer problem where I only have one producer and one consumer. The producer adds products one at a time and the consumer can withdraw several simultaneously. To perform the test, the…
Alberto
  • 339
  • 4
  • 12
0
votes
1 answer

Producer-consumer with interval partitioning

I have an interesting producer-consumer spin-off to implement and I cannot wrap my head around its algorithm. So, every producer will "produce" numbers between the given range (min, max) which give the same reminder to the division by the given…
0
votes
0 answers

Insert data record into database using BlockingCollection in Multiple Producers- Single Consumer

I am fairly new to Producer-Consumer problem so kindly excuse me. I created a sample example- I have 5 tasks in Total- 4 Tasks for producers and 1 Task for consumer as follows: SqlConnection sqlConn = new…