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

Camel - DirectConsumerNotAvailableException No consumers available on endpoint

I have been searching for this issue on Google as well as here on Stackoverflow. I've seen several others report this same exception, and although I understand what the suggested solution is, I am not 100% if I am witnessing the exact same problem…
Beebunny
  • 4,190
  • 4
  • 24
  • 37
0
votes
0 answers

Participant Registration database

I am working on a database to store information about participants that have enrolled in a program. I made up three tables to store information regarding three types of participants. They are; Transport Operators, Artifacts Producers, and Artifacts…
0
votes
1 answer

How to know when all my Producer - Consumer jobs have finished

I have Winforms application that read several network folders and search for files inside this folders, this function receive List folders: private decimal _numberOfFiles; private static List _folders; public delegate void…
0
votes
1 answer

Multiple producers to a queue not working

This is an exercise from Java 7 Concurrency cookbook. Goal is to have multiple producers write Events to a shared queue and a cleaner task (daemon thread) will delete the Events older than 5 seconds from the queue.(Find code below) If I try writing…
K P
  • 861
  • 1
  • 8
  • 25
0
votes
1 answer

PC Queue using TPL?

Original How would I create a Producer-Consumer Queue in C# leveraging the TPL and/or Concurrent Collections? I'm using .NET 4.5+. Here's my first attempt: public class SampleFileProcessor { private readonly BlockingCollection _queue = …
Lee Grissom
  • 9,705
  • 6
  • 37
  • 47
0
votes
2 answers

Multi threaded Linux Socket programming design

I am trying to write a server program which supports one client till now and over the few days i was trying to develop it, I concluded i needed threads. The reason for such a decision was since I take input from a wifi socket and later process it…
0
votes
1 answer

How to determine when my Producer Consumer finish it's job

I have a problem I'm trying to decide how to approach and solve it, I have an application where the user selects certain files and the files is need to be added to my ListView but before I need to check this files (via another class), my problem is…
may danit
  • 25
  • 6
0
votes
0 answers

BlockingCollection multiple thread Producer Consumer

i want to implement multiple thread Producer Consumer, my purpose is insert strings into my Queue, each string represent DOC file that need to be check (simple search inside the document) and in this check is OK the doc file can be add into my…
may danit
  • 25
  • 6
0
votes
2 answers

Finish two tasks then printing something

I have three tasks, one is producer, then consumer and the last one is to print something after finishing the first two. However the code doesn't reach the last task, which means no printing. while (true) { …
user1108948
0
votes
2 answers

Getting Duplicate Objects in Producer/Consumer ConcurrentDictionary C#

I'm stuck on a problem and am wondering if I just have coded something incorrectly. The application polls every few seconds and grabs every record from a table whose sole purpose is to signify what records to act upon. Please note I've left out the…
Arghanoah
  • 3
  • 2
0
votes
0 answers

Implementing JMS Message Consumers

I'm using JMS to send messages between a producer and multiple consumers. I already have the producer that send messages to a queue and now I want to implement multiple consumers that will receive the message according their JMSXGroupID parameter. I…
user2144555
  • 1,315
  • 11
  • 34
  • 55
0
votes
1 answer

how do I access a BlockingQueue from either Swing or the Console?

Whether it's from a GUI or Console, how would either interact with Consumer? Should I simply expose consume as public, or perhaps package-private? That seems like it's stepping into a minefield. Consumer: package net.bounceme.dur.client; import…
Thufir
  • 8,216
  • 28
  • 125
  • 273
0
votes
1 answer

configure kafka to send custom type data

I am pretty new to kafka I have created a producer and consumer greoup using official examples although I want to send thrift bundles from producer and the consumer to get the bundles and store in a bundle array. I have written the producer side…
5ud0
  • 121
  • 1
  • 11
0
votes
1 answer

Writing the contents of a single input stream concurrently to multiple output streams

I'm trying to push the contents of a single input stream to multiple output streams obtained from tcp sockets. I didn't find any existing solution, so I built something from scratch but I really feel I'm reinventing the wheel. My requirements…
bewi
  • 321
  • 3
  • 9
0
votes
1 answer

Structuring critical section for multi threading

I have a producer thread that reads each char and its offset from a source file, then its writes it to a shared circular buffer. I also have a consumer thread that reads the oldest element in the buffer, then writes it to a copy file. The number…