Then make improvement and also generate the shortcoming.
At home, I have an ancient HP server with only one physical CPU with just 1 one core.
At work, I have an access to latest Skylake with 200 cores, perhaps I can manage to run million times.
Will it work?
https://en.wikipedia.org/wiki/Producer–consumer_problem
Inadequate implementation (pasted from URL above):
Code: Select all
int itemCount = 0;
procedure producer()
{
while (true)
{
item = produceItem();
if (itemCount == BUFFER_SIZE)
{
sleep();
}
putItemIntoBuffer(item);
itemCount = itemCount + 1;
if (itemCount == 1)
{
wakeup(consumer);
}
}
}
procedure consumer()
{
while (true)
{
if (itemCount == 0)
{
sleep();
}
item = removeItemFromBuffer();
itemCount = itemCount - 1;
if (itemCount == BUFFER_SIZE - 1)
{
wakeup(producer);
}
consumeItem(item);
}
}