Skip to content

Commit

Permalink
Changed fork for chopstick to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Herrera committed Oct 7, 2021
1 parent 866fc8f commit 63d981c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Implementation on Dining Philosophers problem on C++

## Problem Statement

A certain number of philosophers spend their lives alternating between thinking and eating. They are seated around a circular table. There is a fork placed between each pair of neighboring philosophers. Each philosopher has access to the forks at her left and right. In order to eat, a philosopher must be in possession of both forks. A philosopher may only pick up one fork at a time. Each philosopher attempts to pick up the left fork first and then the right fork. When done eating, a philosopher puts both forks back down on the table and begins thinking. Since the philosophers are sharing forks, it is not possible for all of them to be eating at the same time.
A certain number of philosophers spend their lives alternating between thinking and eating. They are seated around a circular table. There is a chopstick placed between each pair of neighboring philosophers. Each philosopher has access to the chopsticks at her left and right. In order to eat, a philosopher must be in possession of both chopsticks. A philosopher may only pick up one chopstick at a time. Each philosopher attempts to pick up the left chopstick first and then the right chopstick. When done eating, a philosopher puts both chopsticks back down on the table and begins thinking. Since the philosophers are sharing chopsticks, it is not possible for all of them to be eating at the same time.

This was originally formulated in 1965 by Edsger Dijkstra as a student exam exercise.

## Solution

### Waiting State
- The philosopher enters into a waiting state when neighbors are eating
- When its neighbors are done, go for the forks
- When its neighbors are done, go for the chopsticks
- Its neighbors can't enter into the waiting state if there is a neighbor already waiting

## Tests
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

## Problem Statement

A certain number of philosophers spend their lives alternating between thinking and eating. They are seated around a circular table. There is a fork placed between each pair of neighboring philosophers. Each philosopher has access to the forks at her left and right. In order to eat, a philosopher must be in possession of both forks. A philosopher may only pick up one fork at a time. Each philosopher attempts to pick up the left fork first and then the right fork. When done eating, a philosopher puts both forks back down on the table and begins thinking. Since the philosophers are sharing forks, it is not possible for all of them to be eating at the same time.
A certain number of philosophers spend their lives alternating between thinking and eating. They are seated around a circular table. There is a chopstick placed between each pair of neighboring philosophers. Each philosopher has access to the chopsticks at her left and right. In order to eat, a philosopher must be in possession of both chopsticks. A philosopher may only pick up one chopstick at a time. Each philosopher attempts to pick up the left chopstick first and then the right chopstick. When done eating, a philosopher puts both chopsticks back down on the table and begins thinking. Since the philosophers are sharing chopsticks, it is not possible for all of them to be eating at the same time.

This was originally formulated in 1965 by Edsger Dijkstra as a student exam exercise.

0 comments on commit 63d981c

Please sign in to comment.