From 61d709c211132adcc5158ded77c17d690ad5f8da Mon Sep 17 00:00:00 2001 From: Mica White Date: Sun, 10 Mar 2024 11:08:50 -0400 Subject: OwnedLockable --- examples/dining_philosophers.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'examples/dining_philosophers.rs') 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)); -- cgit v1.2.3