From the course: Parallel and Concurrent Programming with C++ Part 2

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Producer-consumer

Producer-consumer - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 2

Start my 1-month free trial

Producer-consumer

- A common design pattern in concurrent programming is the producer-consumer architecture, where one or more threads or processes act as a producer, which adds elements to some shared data structure, and one or more other threads act as a consumer, which removes items from that structure and does something with them. To demonstrate that, I'll be the producer serving up bowls of soup. - I guess that makes me the consumer who eats the soup. I like this demonstration. - After I fill a bowl, I'll add it to this line of bowls that represents a queue. Queues operate on a principle called a first-in-first-out, or FIFO, which means items are removed in the same order that they're put into the queue. The first item that was added will be the first item to be removed. - So when I'm ready to consume another bowl of soup, I'll grab one from this end of the line because it's been in the queue the longest. These bowls of soup represent…

Contents