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 TECHNOLOGYExample 8-8 shows the batched implementation of the producer <strong>and</strong> consumerthread functions.Example 8-8. Batched Implementation of the Producer Consumer Threadsvoid producer_thread(){ int iter_num = workamount - batchsize;int mode1;for (mode1=0; mode1 < batchsize; mode1++){ produce(buffs[mode1],count); }}while (iter_num--){ Signal(&signal1,1);produce(buffs[mode1],count); // placeholder functionWaitForSignal(&end1);mode1++;if (mode1 > batchsize)mode1 = 0;}void consumer_thread(){ int mode2 = 0;int iter_num = workamount - batchsize;while (iter_num--){ WaitForSignal(&signal1);consume(buffs[mode2],count); // placeholder functionSignal(&end1,1);mode2++;if (mode2 > batchsize)mode2 = 0;}}for (i=0;i batchsize)mode2 = 0;}8-29

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

Saved successfully!

Ooh no, something went wrong!