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

Swapping buffers without locks in single producer and multiple consumers

We have use case where data will be updated at regular intervals. But there will be multiple thread reading the data. So the solution which we are thinking is to use double buffers. So the consumer threads will be reading a foreground page while the…
Abhinav
  • 975
  • 4
  • 18
  • 35
0
votes
1 answer

SegFault in Producer/Consumer model

I'm back with yet another segfault i can't seem to conquer. I have figured out exactly what it is, it's something with the char* string line. I use it to break up the bytes to GET this pdf file for a school assignment. Any and all help is…
0
votes
1 answer

Camel; Simple seda to bean route won't work

I'm new to Camel and am trying to setup a very simple app to get used to it with, i'm running the following code: CamelContext cc = (CamelContext)ac.getBean("testCamelContext"); ProducerTemplate template =…
James
  • 1,237
  • 4
  • 22
  • 43
0
votes
1 answer

Two processes single producer / single consumer in Windows. What is better Mutex, Event or Semaphore

I could use either primitive to make it works, but I wonder from a performance perspective, which one is more adequate for such a scenario. I need to synchronize only two processes. There are always two, no more, no less. One Writes to a memory…
cloudraven
  • 2,484
  • 1
  • 24
  • 49
0
votes
1 answer

SegFault with Producer/Consumer File Copy

back with another segfault. Not sure why, as this readdir line is the same one i've been using in other file copy assignments. Below is the code I crafted in lieu of the assignment shared here. I have commented where the segfault occurs in hopes of…
0
votes
2 answers

Creating n amount of background process using fork in C

I'm attempting to create the producer-consumer problem in C using semaphores and shared memory. I've got the semaphores and shared memory working but I'm having trouble determining how to run the individual consumers and producers. This IS…
user1287523
  • 967
  • 3
  • 14
  • 31
0
votes
1 answer

ActiveMQ producer creation and inactivity periods

I have a question relating ActiveMQ and producers. Should I create a producer for every sending of a message? Or use the same one all the time? Is there a performance impact by creating a producer for every sending? Also the connection gets down…
Martin Spa
  • 1,494
  • 1
  • 24
  • 44
0
votes
1 answer

Consumer Producer with double queue

Hello =) I am trying to come up with a pseudocode for the following problem, but I'm a bit confused with the semaphores' sychronization, so I hope someone can help! We have M consumers and M producers and 2 buffers of the same N size. The consumers…
0
votes
2 answers

Indefinitely running Producer/Consumer application

Problem I'm tasked to resolve is (from my understanding) a typical producer/consumer problem. We have data incoming 24/7/365. The incoming data (call it raw data) is stored in a table and is unusable for the end user. We then select all raw data…
Dimitri
  • 6,923
  • 4
  • 35
  • 49
0
votes
3 answers

How to use SynchronousQueue appropriately in producer-consumer model?

I wrote a test example of using SynchronousQueue in producer-consumer model. But it doesn't work well. Below are my codes: public class QueueTest { String input; int pos; BlockingQueue queue; volatile boolean exitFlag; …
JackWM
  • 10,085
  • 22
  • 65
  • 92
0
votes
1 answer

How do I notify a Consumer job that Producer job is done?

Using Spring/Quartz, I have an ProducerJob that is run first. Then I have a ConsumerJob that must wait for the result of ProducerJob (which creates records in the DB). What's the best way for ConsumerJob to be notified of the results of ProducerJob?…
geffchang
  • 3,279
  • 2
  • 32
  • 58
0
votes
1 answer

Queue entry broadcasted to multiple threads

I have a producer thread that generates objects and puts it in a shared queue. I have spawned a bunch of consumer threads that can read from this queue. In an ideal situation every one of my workers will pick up the next job from the queue. But…
sc_ray
  • 7,803
  • 11
  • 63
  • 100
0
votes
3 answers

Java Servlet threading

I have completed the following Java Servlet construction: [I believe the main idea is that of consumer-producer] A Java servlet that receives multiple http POST requests It puts all requests into a Queue [ConcurrentLinkedQueue] All requests in the…
kostaspap
  • 345
  • 4
  • 10
0
votes
1 answer

Boost Threads Producer/Consumer unexpected behavior

I am currently writing an application(using boost) that will have one producer grabbing frames and one consumer reading frames.I added a sleep statement in the producer to simulate the time to grab a frame. I expected the consumer to wait on a…
0
votes
2 answers

How to make a WCF service that acts on a 'Producer\Consumer Queue'?

I have a WCF service, with multiple clients connecting to it and subscribing for events. I also have a Worker Thread that runs in the background, along with the hosted WCF service, and performs operations and pushes items into the 'Producer\Consumer…
John Miner
  • 893
  • 1
  • 15
  • 32
1 2 3
99
100