Example 7-8 Batched Implementation Of The Producer Consumer Threads - Intel ARCHITECTURE IA-32 Reference Manual

Architecture optimization
Table of Contents

Advertisement

Example 7-8 shows the batched implementation of the producer and
consumer thread functions.
Example 7-8
Batched Implementation of the Producer Consumer Threads
void producer_thread()
{
int iter_num = workamount - batchsize;
int mode1;
for (mode1=0; mode1 < batchsize; mode1++)
{
while (iter_num--)
{
}
}
void consumer_thread()
{
int mode2 = 0;
int iter_num = workamount - batchsize;
while (iter_num--)
{
}
for (i=0;i<batchsize;i++)
{
}
}
produce(buffs[mode1],count); }
Signal(&signal1,1);
produce(buffs[mode1],count); // placeholder function
WaitForSignal(&end1);
mode1++;
if (mode1 > batchsize)
mode1 = 0;
WaitForSignal(&signal1);
consume(buffs[mode2],count); // placeholder function
Signal(&end1,1);
mode2++;
if (mode2 > batchsize)
mode2 = 0;
consume(buffs[mode2],count);
mode2++;
if (mode2 > batchsize)
mode2 = 0;
Multi-Core and Hyper-Threading Technology
7
7-41

Advertisement

Table of Contents
loading

Table of Contents