The Dining Philosophers Problem with Java Solution | Deadlocks vs Race Conditions | Geekific

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 3

  • @scoop9887
    @scoop9887 Рік тому

    After 6 years of using java first time, I got a clear vision for concurrency. it's really a great playlist.thank yooooooou

  • @Adi-yi6qq
    @Adi-yi6qq 11 місяців тому +1

    But how does this solution avoid starvation of a particular philosopher?

    • @KishanKumar-mz3xr
      @KishanKumar-mz3xr 4 місяці тому

      Starvation here is because of a philosopher acquiring a left-hand side chopstick and waiting for a right-hand side chopstick which is acquired by another philosopher on its left and is waiting for its right.
      This is resolved first by using synchronised keyword to ensure that only one philosopher can acquire a chopstick at a time (mutual-exclusion) and then breaking the circular dependency in acquiring chopsticks by ensuring one philosopher acquires it's first chopstick in a way different than the others, i.e. If other choose their first chopstick in left, then he must decide his first on its right.