Skip to content

Commit

Permalink
dprint fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Sterling Stein committed Feb 24, 2025
1 parent e4e1cb4 commit 86886c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/concurrency/async-exercises/dining-philosophers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ async fn main() {
let (tx, rx) = mpsc::channel(10);
for (i, name) in PHILOSOPHERS.iter().enumerate() {
let mut left_chopstick = Arc::clone(&chopsticks[i]);
let mut right_chopstick = Arc::clone(&chopsticks[(i + 1) % PHILOSOPHERS.len()]);
let mut right_chopstick =
Arc::clone(&chopsticks[(i + 1) % PHILOSOPHERS.len()]);
if i == PHILOSOPHERS.len() - 1 {
std::mem::swap(&mut left_chopstick, &mut right_chopstick);
}
Expand Down
12 changes: 6 additions & 6 deletions src/concurrency/sync-exercises/dining-philosophers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ The dining philosophers problem is a classic problem in concurrency:

> Five philosophers dine together at the same table. Each philosopher has their
> own place at the table. There is a chopstick between each plate. The dish
> served is spaghetti which requires two chopsticks to eat. Each philosopher
> can only alternately think and eat. Moreover, a philosopher can only eat
> their spaghetti when they have both a left and right chopstick. Thus two
> chopsticks will only be available when their two nearest neighbors are
> thinking, not eating. After an individual philosopher finishes eating, they
> will put down both chopsticks.
> served is spaghetti which requires two chopsticks to eat. Each philosopher can
> only alternately think and eat. Moreover, a philosopher can only eat their
> spaghetti when they have both a left and right chopstick. Thus two chopsticks
> will only be available when their two nearest neighbors are thinking, not
> eating. After an individual philosopher finishes eating, they will put down
> both chopsticks.
You will need a local [Cargo installation](../../cargo/running-locally.md) for
this exercise. Copy the code below to a file called `src/main.rs`, fill out the
Expand Down

0 comments on commit 86886c4

Please sign in to comment.