diff options
| author | Mica White <botahamec@outlook.com> | 2024-03-10 11:08:50 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2024-03-10 11:08:50 -0400 |
| commit | 61d709c211132adcc5158ded77c17d690ad5f8da (patch) | |
| tree | 181195bc8c659721dc48df83a14798f6944623ec /examples/dining_philosophers.rs | |
| parent | ff8c634a303d4a4133accf5fbff375046f022c7f (diff) | |
OwnedLockable
Diffstat (limited to 'examples/dining_philosophers.rs')
| -rw-r--r-- | examples/dining_philosophers.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/examples/dining_philosophers.rs b/examples/dining_philosophers.rs index 9600c8c..f8657df 100644 --- a/examples/dining_philosophers.rs +++ b/examples/dining_philosophers.rs @@ -48,7 +48,10 @@ impl Philosopher { fn cycle(&self) { let key = ThreadKey::lock().unwrap(); thread::sleep(Duration::from_secs(1)); - let forks = LockCollection::new([&FORKS[self.left], &FORKS[self.right]]).unwrap(); + + // safety: no philosopher asks for the same fork twice + let forks = + unsafe { LockCollection::new_unchecked([&FORKS[self.left], &FORKS[self.right]]) }; let forks = forks.lock(key); println!("{} is eating...", self.name); thread::sleep(Duration::from_secs(1)); |
