Example 7-1, Figure 7-2 – Intel ARCHITECTURE IA-32 User Manual

Page 355

Advertising
background image

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

Advertising