experiment: generate producer consumer problem deadlock
Posted: Mon Oct 30, 2017 8:32 pm
I was thinking to compile the following code (or something similar) and run perhaps 100s of thousands of times on high-powered server to see if I can generate the deadlock. Definitely, the goal is not to challenge, but be able to see it in my own eye.
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):
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);
}
}