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

Basic BlockingCollection Producer Consumer in VB.NET

I have been struggling for the last few hours to get a basic implementation of BlockingCollection to work. I cannot seem to find a tutorial in VB.NET for the life of me, so have been trying to get something working from tutorials in C#. I just want…
Henry Ing-Simmons
  • 1,362
  • 5
  • 18
  • 25
0
votes
0 answers

shared semaphores in linux do not post

I'm having a problem trying to implement a solution to the producer-consumer problem in linux. I'm supposed to use a shared semaphore to synchronize across different processes. I understand the concept of signalling alternate semaphores like this…
docaholic
  • 613
  • 9
  • 29
0
votes
2 answers

Producer consumer multiple mutex needed to access critical section?

There are 3 tools. A consumer needs 2 tools to modify the buffer. If consumer A takes the 2 tools and consumer B takes 1, consumer B will have to wait for another tool to be released. I am not sure if I'm thinking about this problem in the right…
0
votes
2 answers

Strange Behavior with Threading and Timer

I explain my situation. I have a producer 1 to N consumers pattern. I'm using blocking collections and everything is working well. Doing some test I noticed this strange behavior: I was testing how long my manipulation of data took in my…
qwark
  • 493
  • 1
  • 4
  • 15
0
votes
1 answer

activemq delete consumed messages

I am using ActiveMQ in my app. My question is how to delete messages that ı consumed successfully from kahadb. Because if it is not deleted, my db.data file is growing up constantly. Here is my consumer; ActiveMQConnectionFactory…
turkuaz07
  • 101
  • 1
  • 10
0
votes
1 answer

When are mutexs required for producer/consumer problems?

if there is 1 producer, 1 consumer and a buffer of >1 size is insert mutex required? is remove mutex required? if there is 1 producer, 1 consumer and a buffer of 1 size is insert mutex required? is remove mutex required? if there is >1 producer, >1…
Gunslinger
  • 1,456
  • 7
  • 22
  • 36
0
votes
2 answers

producer consumer using posix

I have a Standard Producer Consumer problem for bounded buffer.Whenever i give unequal number of producer or consumer the Program does not terminate. I have limited the number of insertion or deletion to 50 I would like to know why the above…
0
votes
2 answers

Read from file and store into buffer

Could anyone please tell me that in producer consumer problem, How one can read a line from file and store into buffer of size 10 ? static char buf[10][256]; void *producer( void *var) { char line[256]; int i; for(;;) { if(feof) …
denizen
  • 458
  • 1
  • 5
  • 15
0
votes
0 answers

IPC - Ways for not consuming CPU

I am writing in C a program with using Producer-Consumer. I have a process comunicating with N consumers via a shared memory. In order to achieve this I am using semaphores. However my process needs to wait uncertain time for a consumer to send some…
user2147971
  • 135
  • 4
0
votes
1 answer

Faster producer Slow consumer with critical times

I have a problem with producers and consumers. I have one producer that produces data very fast and it takes data with a specific period from an external server. I have three consumers which need that data. The consumers do some processing on this…
barp
  • 6,489
  • 9
  • 30
  • 37
0
votes
1 answer

java while(true) polling a queue not getting executed

I am learning java and I am implementing a basic producer-consumer usecase. I have a queue and some Producers that are inserting stuff into this queue. I also have one Consumer that implements Callable. Here is the implementation of Consumer: public…
Erben Mo
  • 3,528
  • 3
  • 19
  • 32
0
votes
1 answer

Java threads notify() wait() for faster calculation

I must create simple application with threads. Task: faster calculation than serial processing. I must use methods notify() or notifyAll(), wait(), interrupt() and operator synchronized. I tried solve this by example from book. This example is…
0
votes
0 answers

java - blockingQueue with condition Issue

I've two threads the first one execute some tasks (called TaskManager) and the second listen to events and store them in a queue (called EventManager). EventManager should be woken up and start running only if the queue is not empty and some…
IgalS
  • 31
  • 3
0
votes
5 answers

Understanding the use of Synchronized

I am trying to understand the use of Synchronized block. In the below program, Inside a produce and consumer method I have created a synchronized block and if I lock it by using lock1(object). I am getting the following error, why is this, why…
User27854
  • 824
  • 1
  • 16
  • 40
0
votes
0 answers

generating images in single producer single consumer model

I have the following setting: a webpage is generating requests for images which are rendered on the server implemented in C++. The object generating images is very expensive to initialize so it is kept initialized in 3-4 copies on the server. There…
iggy
  • 1,613
  • 1
  • 18
  • 35