Deadlock example in the book

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Deadlock example in the book

      The book talks about the dinning philosophers problem at page 703-704. The book mentions that deadlock would happen if every philosopher grabbed his left chopstick and hold onto it cause nobody can have his right chopstick.

      Here is a quote from page 704:

      "If you find yourself at a table with four other people and only five chopsticks between you, simply agree to pick up the left chopstick first and the right chopstick second. When you are ready to stop eating and start thinking, put them down in reverse order. Believe it or not, no deadlock will happen, and no one will starve."

      Everybody Picking up the left chopstick is exactly what would cause the deadlock. I don't understand how this would work. If the deadlock already happens, how putting the right chopstick first could help?
    • The key here is that not everyone is agreeing to pick up the left chopstick first, only the even numbered diners, the odd numbered diners are picking up the right chopstick first. To simplify this situation lets break it down between 2 people and 3 chopsticks, each have 1 chopstick they are guaranteed to get in this case (not in the case of a full table), and also 1 chopstick that they both have mutually exclusive access to. So lets run through an attempt to eat.

      - Both philosophers grab their chopstick, one starting on the left and one starting on the right. The first one to pick up their chopstick will likely (if quick enough) also be able to grab the second chopstick first, causing the losing philosopher to think for a while instead.

      - By the time the eating philosopher has done eating, it is likely that he wants to think for a while, and the thinking philosopher would like to eat now, this should be adequate enough time that both philosophers are able to eat and think in an even manner, however if no time is spent thinking than the faster philosopher may simply win in every situation which is why the thinking stage is important.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • mholley519,

      What you said is already said in the book: if odd and even numbered philosophers having different picking orders, that would avoid deadlock.

      What confuses me is the quoted text. It doesn't say anything about odd and even numbered people. In fact sounds like it suggests everyone picking up the left chopstick first, and to avoid deadlock, everyone simply puts down the right chopstick if he is done eating, but that's not true.
    • Well you need to read it in the context of the entire section.

      ​If you find yourself at a table with four other people and only five chopsticks between
      you, simply agree (just you) to pick up the left chopstick first and the right chopstick second.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz