Multi-Core and Hyper-Threading Technology
7
7-9
overhead when buffers are exchanged between the producer and
consumer. To achieve optimal scaling with the number of cores, the
synchronization overhead must be kept low. This can be done by
ensuring the producer and consumer threads have comparable time
constants for completing each incremental task prior to exchanging
buffers.
Example 7-1 illustrates the coding structure of single-threaded
execution of a sequence of task units, where each task unit (either the
producer or consumer) executes serially (shown in Figure 7-2). In the
equivalent scenario under multi-threaded execution, each
producer-consumer pair is wrapped as a thread function and two threads
can be scheduled on available processor resources simultaneously.
Example 7-1
Serial Execution of Producer and Consumer Work Items
for (i = 0; i < number_of_iterations; i++) {
producer (i, buff); // pass buffer index and buffer address
consumer (i, buff);
}(
Figure 7-2
Single-threaded Execution of Producer-consumer Threading Model
P(1)
P(1)
C(1)
C(1)
P(1)
Main
Thread
Summary of Contents for ARCHITECTURE IA-32
Page 1: ...IA 32 Intel Architecture Optimization Reference Manual Order Number 248966 013US April 2006...
Page 220: ...IA 32 Intel Architecture Optimization 3 40...
Page 434: ...IA 32 Intel Architecture Optimization 9 20...
Page 514: ...IA 32 Intel Architecture Optimization B 60...
Page 536: ...IA 32 Intel Architecture Optimization C 22...