Results 1 to 2 of 2
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Rep Power

    Default First attempt at concurrent programming. i think I have reached deadlock.

    I am writing a program which is a variation of the dining philosophers problem. I am solving it using just wait(), notify() and sleep().

    I have managed to get it to work for 2 out of 6 of my philosophers. However the other 4 (apart from 1 who seems to love a particular fork) do nothing and just sit there even when their cutlery is available to use.

    I have been over and over my code and, based on my understanding of concurrent programming in Java, I can't see anything wrong. I think there is something wrong with where I think I am instructing a piece of cutlery to be made available when it, in fact, is not being made available or maybe the other philosophers are just not checking.

    Below is the code ran on each of the threads (each philosopher is a thread). Are there any obvious mistakes that I have made?

    The idea of the code is that if the item of cutlery is available, it will be picked up, then the other piece will be picked up (This will be always be available when needed as I have specified to only ever go for knives if you have your allocated fork). The philosopher will eat (sleep) for a few seconds before setting both pieces to available and then thinking (sleeping). Whilst they are thinking, other philosophers have the occortunity to pick up the items - but none of them ever do!


    Java Code:
    Last edited by kkid; 03-16-2014 at 11:38 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: First attempt at concurrent programming. i think I have reached deadlock.

    Seeing a whole working program that would compile and execute and allow debugging would make it easier to see the problem.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. attempt to obtain deadlock statement
    By voipp in forum Threads and Synchronization
    Replies: 8
    Last Post: 12-15-2013, 10:32 PM
  2. concurrent programming
    By abdullahansari in forum New To Java
    Replies: 1
    Last Post: 12-02-2010, 08:33 PM
  3. Replies: 1
    Last Post: 05-31-2009, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts