Producer/Consumer Pattern
- The Producer/Consumer problem is a classic Concurrent programming problem.
- The Producer/Consumer Design Pattern is the standard, pattern-based design to solve these types of problem.
- The idea is that the Producer produces "something" (as output) and the Consumer(s) process or consumes the "something" (as input).
- The Producer has no knowledge of when or if the Consumer(s) exists, just that it will produce "something".
- The Consumer(s) have no knowledge of the Producer, all they know is that when the "something" is there, they want it.
- They also have no knowledge of other Consumers.
- Only one Consumer will consume each output from the Producer.
- The overriding limitation is that the Producer will not overproduce and the Consumer will not consume things that don't exist.
- The Producer and Consumer(s) are coded as separate threads (Concurrency!)
- Let's look at the Consumer and Producer code in
downloads/multithreading.
References:
https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem