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

How to trigger a background thread when my queue has something to process

I am using ConcurrentQueue to store messages from multiple threads. How to create some background thread which will automatically get triggered when my queue has something in it?
Pavan Tiwari
  • 3,077
  • 3
  • 31
  • 71
0
votes
1 answer

Variable scope in multithreading, why my object reference is lost?

Briefly under a single producer - single consumer scenario, I used a mutable object for synchronization and passing data and messages between producer and consumer. Shared buffer is a ConcurrentQueue of byte arrays. To implement a circular buffer…
Xaqron
  • 29,931
  • 42
  • 140
  • 205
0
votes
0 answers

calculating producer-consumer flow matrix - earth movers histogram comparison

earth movers algorithm for histogram comparison is based on the producer-consumer problem Suppose we have m producers and each producer comes with a weight representing the amount of product he has. We denote producer set P as: P = {(p1, w1),…
Shahaf Stein
  • 165
  • 2
  • 14
0
votes
1 answer

Multithreading Producer and Consumer with Semaphores in C

I am having issues getting my project to work and was hoping someone could assist. The guidelines are as follows: You will use the pthread package to create 4 producer threads and 4 consumer threads. Each producer thread inserts character ‘X’ into…
CW2272
  • 183
  • 1
  • 10
0
votes
1 answer

How to retrieve older messages in ActiveMQ queue

Iam working on ActiveMQ application where iam using a consumer which uses Session.CLIENT_ACKNOWLEDGE. Iam sending the messages received from queue in consumer to a webservice.Assume if i don do message.acknowledge() all the messages sent to…
Chetan Sistla
  • 165
  • 2
  • 16
0
votes
0 answers

Can't read a file using producer-consumer thanks to processes and semaphores

Generalities and functioning of my program NB : you will be able to test my program (only one file, containing the main function). I give you the entire code at the end of this question. I wrote a program which can be used to illustrate the…
0
votes
1 answer

No output data at all for Producer/Consumer threading

Edit: I have a producer class that send some data to the SharedBuffer class. This data is added to an ArrayList with the limit set to 100. There is no problem with adding data to said list, but the consumer class does not manage to get any of the…
0
votes
1 answer

How to properly write RabbitMQ Publisher on Java?

Do we need to create individual channels for each thread or use the same channel for all threads? Also the same question about connection. Do we need to use different connections for each thread or a single connection? What is the difference when we…
Oleksandr
  • 3,574
  • 8
  • 41
  • 78
0
votes
2 answers

producer-consumer c - segmentation fault for bigger values

I am doing the one producer-one consumer problem with two threads in c. I did it using a shared linked list in which producer puts something and consumer takes it from the same list. I have to run my code with 2 values N and B(N being the size of…
0
votes
1 answer

How to write a samplest kafka spout with New Kafka Consumer API?

Likes storm-kafka-client,I was used storm-kafka-client but cannot work well,and write a new spout not work too. Who can help me to write a samplest kafka spout.
0
votes
2 answers

Multi-Thread Producer/Consumer Synchronization Issues

I am having issues with two threads that dont seem to synchronize properly. I basically have an boolean value names "occupied". It is set to false when no thread is started. but when one starts, the thread sets occupied is true I have a class that…
0
votes
1 answer

Single producer to multi consumers (Same consumer group)

I've try before sending message from single producer to 2 different consumer with DIFFERENT consumer group id. The result is both consumer able to read the complete message (both consumers getting the same message). But I would like to ask is it…
不好笑
  • 105
  • 3
  • 14
0
votes
1 answer

Array Blocking Queue with capacity 1 wrong behavior producer consumer

I made the following producer consumer problem with blocking queue with capacity 1. So that producer can produce only one item but running the code producer can produce 2 items and consumer can consume even though queue is empty. please help in…
0
votes
2 answers

Trigger SheduledExecutor with blockingQueue Java

I'm currently working on java application which has a scenario of multiple producers adding tasks to a queue and whenever queue is not empty tasks should be executed at predefined rate. (using multiple threads to maintain execution rate) After…
0
votes
0 answers

Kafka topic description does not give consistent result

I am using Kafka 0.10.0.0, in a cluster with 3 nodes I have auto topic creation enabled on brokers and on all brokers I have added properties for specify number of partition and replicas num.partitions=2 default.replication.factor=2 Now when I…