Producer-consumer threading models, Producer-consumer threading models -10, Figure 7-3 – Intel ARCHITECTURE IA-32 User Manual

Page 356

Advertising
background image

IA-32 Intel® Architecture Optimization

7-10

Producer-Consumer Threading Models

Figure 7-3 illustrates the basic scheme of interaction between a pair of
producer and consumer threads. The horizontal direction represents
time. Each block represents a task unit, processing the buffer assigned to
a thread. The gap between each task represents synchronization
overhead. The decimal number in the parenthesis represents a buffer
index. On an Intel Core Duo processor, the producer thread can store
data in the second-level cache to allow the consumer thread to continue
work requiring minimal bus traffic.

The basic structure to implement the producer and consumer thread
functions with synchronization to communicate buffer index is shown in
Example 7-2.

Figure 7-3

Execution of Producer-consumer Threading Model on a Multi-core
Processor

Main

Thread

P(2)

P(1)

P(2)

P(1)

C(1)

C(2)

C(1)

C(2)

P(1)

P: producer

C: consumer

Advertising