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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MULTICORE AND HYPER-THREADING TECHNOLOGYExample 8-2. Basic Structure of Implementing Producer Consumer Threads (Contd.)}b) Basic structure of a consumer threadvoid consumer_thread(){ int mode2 = 0; // first iteration start with buffer 0, than alternateint iter_num = workamount - 1;while (iter_num--) {}WaitForSignal(&signal1);consume(buffs[mode2],count); // placeholder functionSignal(&end1,1);mode2 = 1 - mode2;}consume(buffs[mode2],count);It is possible to structure the producer-consumer model in an interlaced manner suchthat it can minimize bus traffic <strong>and</strong> be effective on multicore processors withoutshared second-level cache.In this interlaced variation of the producer-consumer model, each scheduling quantaof an application thread comprises of a producer task <strong>and</strong> a consumer task. Two identicalthreads are created to execute in parallel. During each scheduling quanta of athread, the producer task starts first <strong>and</strong> the consumer task follows after the completionof the producer task; both tasks work on the same buffer. As each taskcompletes, one thread signals to the other thread notifying its corresponding task touse its designated buffer. Thus, the producer <strong>and</strong> consumer tasks execute in parallelin two threads. As long as the data generated by the producer reside in either thefirst or second level cache of the same core, the consumer can access them withoutincurring bus traffic. The scheduling of the interlaced producer-consumer model isshown in Figure 8-4.Thread 0P(1)C(1)P(1)C(1)P(1)Thread 1P(2)C(2)P(2)C(2)Figure 8-4. Interlaced Variation of the Producer Consumer Model8-8

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

Saved successfully!

Ooh no, something went wrong!