https://github.com/msabr/philosophers_1337
The classic dining philosophers problem 🍽️ simulates concurrent philosophers competing for forks, illustrating synchronization techniques to prevent deadlocks, starvation, and race conditions.
https://github.com/msabr/philosophers_1337
1337cursus 1337school 42cursus 42projects 42school c multiprocessing multithreading mutex philosopher philosophers philosophers-42 philosophers-dinner-problem philosophers-problem philosophers42 prossesing semaphore semaphores treads
Last synced: 4 months ago
JSON representation
The classic dining philosophers problem 🍽️ simulates concurrent philosophers competing for forks, illustrating synchronization techniques to prevent deadlocks, starvation, and race conditions.
- Host: GitHub
- URL: https://github.com/msabr/philosophers_1337
- Owner: msabr
- Created: 2025-05-18T14:18:47.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-08-29T17:00:46.000Z (10 months ago)
- Last Synced: 2025-08-29T19:25:35.856Z (10 months ago)
- Topics: 1337cursus, 1337school, 42cursus, 42projects, 42school, c, multiprocessing, multithreading, mutex, philosopher, philosophers, philosophers-42, philosophers-dinner-problem, philosophers-problem, philosophers42, prossesing, semaphore, semaphores, treads
- Language: C
- Homepage:
- Size: 24.5 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHILOSOPHERS - 42 Network
Implementation of the **Dining Philosophers Problem**, a classic concurrency challenge, using **threads (mandatory)** and optionally **processes/semaphores (bonus)**.
---
## 📖 The Dining Philosophers Problem
The **Dining Philosophers Problem** is a classic concurrency challenge first formulated by **Edsger W. Dijkstra** in 1965. It models synchronization, resource sharing, and deadlock avoidance in concurrent systems.
---
### 🪑 Problem Setup
- A group of philosophers sit around a round table.
- There are as many forks as philosophers, one between each pair.
- Each philosopher can:
- **Eat**, **sleep**, or **think**
- To **eat**, a philosopher must pick up **two forks** (the one to their right and the one to their left).
- Forks are shared resources and can only be held by one philosopher at a time.
- Philosophers cannot eat unless they have both forks.
- Philosophers never do more than one action at a time.
---
### 🔄 The Challenge
Naive implementations lead to issues such as:
- 🛑 **Deadlock**: All philosophers pick up one fork and wait indefinitely for the other.
- 🧍 **Starvation**: Some philosophers may never get to eat.
- 💥 **Race Conditions**: Without proper synchronization, concurrent access corrupts shared data.
---
## ❓ Problem Statement
**How can multiple concurrent threads safely share resources (forks) without deadlocks, starvation, or data races — using only mutexes and thread primitives?**
The project simulates N philosophers sitting around a table. Each must:
- **Take two forks** (mutexes)
- **Eat** for a defined duration
- **Sleep**
- **Think**
- Repeat the cycle indefinitely
A monitor thread ensures no philosopher dies from starvation (exceeding `time_to_die` without eating).
---
## 🎯 Objective
Simulate a group of philosophers sitting around a table. Each must:
- 🥢 Take forks
- 🍝 Eat
- 😴 Sleep
- 💭 Think
Without creating **deadlocks** or **data races**.