 | | A more specialized producer/consumer relationship, often used in pipelines for signal processing applications, uses a technique known as double buffering. Using double buffering, threads act as both producer and consumer to each other. In the example of double buffering shown in Figure 2-5,one set of buffers contains unprocessed data and another set contains processed data. One thread—the I/O thread—obtains unprocessed data from an I/O device and places it in a shared buffer.(In other words, it's the producer of unprocessed data.) The I/O thread also obtains processed data from another shared buffer and writes it to an I/O device. (That is, it's the consumer of processed data.) A second thread—the calculating thread—obtains unprocessed data from the shared buffer filled by the I/O thread, processes it, and places its results in another shared buffer. The calculating thread is thus the consumer of unprocessed data and the producer of processed data. | |
|