13.07.2015 Views

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

MULTICORE AND HYPER-THREADING TECHNOLOGY8.2.3.1 Producer-Consumer Threading ModelsFigure 8-3 illustrates the basic scheme of interaction between a pair of producer <strong>and</strong>consumer threads. The horizontal direction represents time. Each block represents atask unit, processing the buffer assigned to a thread.The gap between each task represents synchronization overhead. The decimalnumber 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 consumerthread to continue work requiring minimal bus traffic.MainThreadP(1)P(2)P(1)P(2)P(1)P: producerC: consumerC(1)C(2)C(1)C(2)Figure 8-3. Execution of Producer-consumer Threading Modelon a Multicore ProcessorThe basic structure to implement the producer <strong>and</strong> consumer thread functions withsynchronization to communicate buffer index is shown in Example 8-2.Example 8-2. Basic Structure of Implementing Producer Consumer Threads(a) Basic structure of a producer thread functionvoid producer_thread(){ int iter_num = workamount - 1; // make local copyint mode1 = 1; // track usage of two buffers via 0 <strong>and</strong> 1produce(buffs[0],count); // placeholder functionwhile (iter_num--) {}Signal(&signal1,1); // tell the other thread to commenceproduce(buffs[mode1],count); // placeholder functionWaitForSignal(&end1);mode1 = 1 - mode1; // switch to the other buffer8-7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!