https://github.com/souleeater99/philosophers
About Section Philosophers 🍝⏳ – A 42 School project implementing the classic Dining Philosophers problem in C. Core Concepts: Multithreading (pthreads) & Mutex synchronization Multiprocessing (bonus) with Semaphores Deadlock/starvation prevention strategies Precise timing & thread-safe logging Key Features: ⚙️ Concurrent resource management
https://github.com/souleeater99/philosophers
1337 1337cursus 42 42network 42school c concurrency dining-philosophers dining-philosophers-problem multiprocessing multithreading mutex operating-system semaphore
Last synced: 12 months ago
JSON representation
About Section Philosophers 🍝⏳ – A 42 School project implementing the classic Dining Philosophers problem in C. Core Concepts: Multithreading (pthreads) & Mutex synchronization Multiprocessing (bonus) with Semaphores Deadlock/starvation prevention strategies Precise timing & thread-safe logging Key Features: ⚙️ Concurrent resource management
- Host: GitHub
- URL: https://github.com/souleeater99/philosophers
- Owner: SouleEater99
- Created: 2024-05-09T12:00:06.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-25T16:58:00.000Z (about 1 year ago)
- Last Synced: 2025-03-25T17:48:34.516Z (about 1 year ago)
- Topics: 1337, 1337cursus, 42, 42network, 42school, c, concurrency, dining-philosophers, dining-philosophers-problem, multiprocessing, multithreading, mutex, operating-system, semaphore
- Language: C
- Homepage: https://github.com/SouleEater99/Philosophers
- Size: 1.72 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🧠 Philosophers - When Concurrency Meets Spaghetti
*A 42 School solution to the Dining Philosophers problem using threads/mutex (mandatory) and processes/semaphores (bonus)*
[](LICENSE)
[](https://github.com/42School/norminette)
## 🚀 Features
### Mandatory
- Thread-per-philosopher architecture
- Mutex-protected forks to prevent data races
- Real-time death checks (millisecond precision)
- Thread-safe logging with timestamps
### Bonus
- Process-based philosophers (`fork()`)
- Semaphore-managed fork pool
- Inter-process communication
## 🔍 Problem Statement
Simulate philosophers alternating between eating, sleeping, and thinking without:
- Deadlocks (circular wait)
- Starvation (unfair resource allocation)
- Data races (using mutex/semaphore)
## 🛠️ Installation
```bash
git clone https://github.com//Philosophers.git
cd Philosophers
make # Mandatory
make bonus # Bonus
```
## 💻 Usage
#### Mandatory:
./philo 5 800 200 200 # 5 philos, die after 800ms, 200ms eat/sleep
#### Bonus:
```
./philo_bonus 4 500 200 200 3 # Stop after 3 meals per philosopher
```
## 📚 Implementation Details
* **No Global Variables:** Strict parameter passing between threads/processes
* **Performance:** Optimized death-check algorithm
* **Edge Cases:** 1-philosopher, 0-meals, large input handling
## 🌟 Learning Outcomes
* **Concurrency Control:** Mutex vs. semaphore tradeoffs
* **Precision Timing:** `gettimeofday` microsecond accuracy
* **Synchronization Patterns:** Resource contention strategies