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

Producer Consumer segmentation fault (core dumped)

Hi im trying to do the producer/consumer problem on a ubuntu virtual image using vmware. I got the code from here : http://macboypro.wordpress.com/2009/05/25/producer-consumer-problem-using-cpthreadsbounded-buffer/ but i just keep getting…
0
votes
1 answer

Producer Consumer in C# with multiple (parallel) consumers and no TPL Dataflow

I am trying to implement producer/consumer pattern with multiple or parallel consumers. I did an implementation but I would like to know how good it is. Can somebody do better? Can any of you spot any errors? Unfortunately I can not use TPL…
Laszlo
  • 302
  • 1
  • 10
0
votes
1 answer

Kafka Consumers Work Queue

We have the following scenario in an SOA application. ServiceA produces some jobs which need to be processed by instances of ServiceB asynchronously. Essentially, this translates to a Work Queue problem where each worker is an instance of ServiceB.…
0
votes
1 answer

Share a BlockingCollection across processes

Is there a way to share the same BlockingCollection across two .net applications, with one application producing new items, and the other consuming them? The inter-process communication options I found all appear to involve serializing and…
HugoRune
  • 13,157
  • 7
  • 69
  • 144
0
votes
1 answer

Multithreading in Python: Processing Similar to Producer Consumer

In Python 2.7, how can one know when a thread has finished such that one can maintain a constant buffer of running threads, at least until all processing has finished? I am trying to keep a buffer of threads (similar to a producer/consumer problem…
ethnhll
  • 91
  • 5
0
votes
1 answer

How to implement fair usage policy of threads in API backend?

I am building an REST API in Java which I would be exposing to the outside world. People who would be invoking the API would have to be registered and would be sending their userid in the request. There would be a maximum of, say, 10 concurrent…
0
votes
1 answer

Weird issue with returning empty struct instead of NULL

Context I am working on a consumer & producer multi-threaded program. The program has a shared variable num_elem that is incremented in the producer and decremented in the consumer. num elem is providing information for a circular buffer that is…
T.Woody
  • 1,142
  • 2
  • 11
  • 25
0
votes
0 answers

Similar paradigms as readers-writers prob and producer-consumer prob

for my Operating Systems Networking class, we must come up with a common paradign that is faced when developing operating systems and propose a solution to the paradigm. Some possible topics suggested in class were: Producer/Consumer problem,…
0
votes
2 answers

notify threads in a different Object

How do I notify a thread from one object to another in the below program without using synchronized methods in the following producer and consumer problem. I am using a queue class for the put and get methods and using wait() and notify() in the…
0
votes
0 answers

Different Multithread Producer-Consumer with memory constraint

I'm facing a problem as an exercise, which is a small variant of classical producer-consumer using two threads. One thread is the producer (P), and the other one the consumer (C). I have to process a big file, but I can only read it in pieces, like…
0
votes
0 answers

Monitor in C using Semaphore

I am trying to implement a monitor in C to use to solve the producer/consumer problem. I understand the producer/consumer problem and I also understand the solution using monitors. However, I am having a hard time translating that to C without using…
user3060454
  • 61
  • 1
  • 8
0
votes
1 answer

confusion with semaphore definitions

For semaphore implementations, what does process specify? In the context of the producer/consumer problem, is the process the producer method/Consumer method? Or is it P() if we are in P() and the value is less than 0? P() { …
0
votes
1 answer

Producer-Consumer implemented with clone2 and semaphores in c++

I am implementing a producer consumer with c++ using clone2() and semaphores but it has an unexpected behavior. Here is the code: #include #include #include #include #include #include…
Juan Rivillas
  • 897
  • 2
  • 9
  • 23
0
votes
0 answers

Producer Consumer model for BFS

I'm trying to do a maze solving algorithm, and I've decided to use BFS to try and find the shortest path (since I have no way of determining how close I am to the exit, I'm not sure how I could use something A*). In an effort to speed things up,…
docaholic
  • 613
  • 9
  • 29
0
votes
1 answer

How do I pass the data from one thread to three other threads?

I have to write an application which consists of four threads: thread generates some data (producer thread); thread gets the data from producer thread and does Action1(data); thread gets the data from producer thread and does Action2(data); thread…