Skip to content

mdev9/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🍽️ Philosophers – Dining Philosophers Simulation

Welcome to Philosophers, a multithreaded simulation of the classic dining philosophers problem! 🥳✨ This project explores concurrency and synchronization in programming, utilizing mutexes to ensure that our philosophers dine without starving. 🥢🍽️💻

📝 Project Overview

In this project, we simulate the dining philosophers problem, where philosophers alternately think 🤔 and eat 🍜, sharing limited resources (forks 🍴) while avoiding deadlock 🔒 and ensuring synchronization ⚖️. This project is a great way to deepen your understanding of multithreading and synchronization techniques. 🌐🔍

Key Features:

  • 🔹 Multithreading: Utilizes threads to simulate philosophers' behavior. 🧵🧑‍🤝‍🧑
  • 🔹 Mutex Synchronization: Implements mutex locks 🔐 to manage access to shared resources.
  • 🔹 Optimized Resource Management: Avoids deadlocks and ensures that each philosopher gets a chance to eat. 🍽️⚙️

📦 Installation & Setup

To get started with Philosophers, follow these simple steps:

  1. Clone the repository:

    git clone https://github.com/mdev9/philosophers.git
    cd philosophers
  2. Compile the project:

    cd philo
    make

    or with bonuses:

    cd philo_bonus
    make
  3. Run the simulation:

    ./philo [number_of_philosophers] [time_to_die] [time_to_eat] [time_to_sleep] [optional: max_eat_count]

    or with bonuses:

    ./philo_bonus [number_of_philosophers] [time_to_die] [time_to_eat] [time_to_sleep] [optional: max_eat_count]
  • number_of_philosophers: Total number of philosophers. 👨‍🍳👩‍🍳
  • time_to_die: Time (in milliseconds) before a philosopher dies from starvation. ⏳
  • time_to_eat: Time (in milliseconds) it takes for a philosopher to eat. 🍲
  • time_to_sleep: Time (in milliseconds) a philosopher will sleep. 😴
  • max_eat_count (optional): Maximum number of times each philosopher should eat. 🍽️🔁

🛠️ How to Use the Simulation

Here’s an example demonstrating how to run the philosophers' simulation:

./philosophers 5 800 200 200

This command will run a simulation with 5 philosophers, where each has 800 milliseconds before they die of starvation, takes 200 milliseconds to eat, and sleeps for 200 milliseconds. 🥱💤

🔍 Project Goals

The main objectives of the Philosophers project include:

  • 🌐 Simulating the classic dining philosophers problem.
  • 🔍 Understanding and implementing multithreading and synchronization concepts.
  • 📈 Enhancing skills in parallel programming and optimization. 💪🎯

Thank you for checking out Philosophers! 🌟 May your philosophers dine in harmony! 🍴✨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published