OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 26, 2018 10:41 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: experiment: generate producer consumer problem deadlock
PostPosted: Mon Oct 30, 2017 8:32 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 309
Location: San Jose San Francisco Bay Area
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):

Code:
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);
    }
}

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: experiment: generate producer consumer problem deadlock
PostPosted: Tue Oct 31, 2017 12:00 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3101
Location: Chichester, UK
ggodw000 wrote:
Will it work?

Isn't the point of an experiment to test that sort of question?


Top
 Profile  
 
 Post subject: Re: experiment: generate producer consumer problem deadlock
PostPosted: Tue Oct 31, 2017 5:30 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 309
Location: San Jose San Francisco Bay Area
YUP, i guess i will jump right in.

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group