Skip to content

Philosophers is a project that simulates the classic Dining Philosophers Problem to demonstrate concurrency control, resource management, and synchronization techniques, often using threads or processes to handle potential deadlocks and starvation.

Notifications You must be signed in to change notification settings

doooriian/Philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation


42 Logo

Philosophers

A synchronization and concurrency challenge from 42 School based on the Dining Philosophers Problem.

Philosophers Badge

GitHub code size in bytes Code language count GitHub top language GitHub last commit


✨ Overview

Philosophers is an individual project at 42 School that challenges students to solve the classic Dining Philosophers Problem. The task involves creating a simulation where multiple philosophers, seated at a circular table, alternate between thinking, eating, and sleeping, while sharing limited resources (forks). The main challenge is to ensure proper synchronization and avoid common pitfalls like deadlocks and starvation.

To implement a solution, I adhered to the specifications provided by the 42 project guidelines and used various strategies to coordinate philosopher actions efficiently.


📑 Key Features

  • Concurrent Simulation: Each philosopher is modeled as a separate process or thread, demonstrating inter-process communication and synchronization.
  • Deadlock Prevention: Implements strategies to avoid deadlocks and resource contention.
  • Efficient Resource Management: Ensures timely access to forks while promoting fair resource distribution among all philosophers.
  • Clear Status Updates: Logs each philosopher's actions (e.g., picking up forks, eating, sleeping, thinking) to help visualize the simulation progress.

🛠️ Technologies Used

  • C — Core programming language.
  • POSIX Threads or Processes — For creating concurrent simulations.
  • Makefile — Used for building and automating the project.

🚀 How to Build and Run

Clone the repository and use the following commands in your terminal:

# Compile the project
make all

# Remove object files
make clean

# Remove object files and executable
make fclean

# Clean and recompile
make re

Run the executable with the required arguments. The program accepts parameters such as the number of philosophers, time to die, time to eat, time to sleep, and optionally the number of times each philosopher must eat.

Example usage:

./philo 5 800 200 200

Example with a meal limit:

./philo 5 800 200 200 7

🧪 Testing

The simulation was tested under multiple scenarios to ensure robustness and correctness:

  • Validating with various numbers of philosophers.
  • Monitoring behavior under high contention for forks.
  • Confirming that no deadlocks or starvation occur during long runs.
  • Checking the simulation output for proper chronological status updates of each philosopher.

Additional custom scripts were used to automate the testing and verify the expected results.

📚 Resources

✅ Results

Here’s my score for the Philosophers project:

Philosophers Grade


📬 Contact

Feel free to reach out or contribute to this project on GitHub!

About

Philosophers is a project that simulates the classic Dining Philosophers Problem to demonstrate concurrency control, resource management, and synchronization techniques, often using threads or processes to handle potential deadlocks and starvation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published