Skip to content

Instantly share code, notes, and snippets.

@ruiqurm
ruiqurm / philosopher.rs
Last active December 28, 2022 06:17
philosopher dining problem
use std::sync::mpsc;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use rand::Rng;
struct Fork;
struct Philosopher {
name: String,
left_fork: Arc<Mutex<Fork>>,