βThe art of thinking, eating, and avoiding deadlocks.β
Philosophers is a concurrency project from 42 School, completed on 31 July 2024.
It implements a simulation of the classic Dining Philosophers Problem, where multiple threads (philosophers) must alternate between thinking, eating, and sleeping while competing for shared resources (forks) without causing deadlocks or race conditions.
- Understand and apply thread management in C
- Use mutexes to protect shared resources
- Prevent deadlocks and starvation
- Implement timing and logging for precise simulation
- π§΅ Multithreading with
pthread - π Mutexes for synchronization
- π Deadlock and starvation prevention
- β±οΈ Timing accuracy with
usleep/gettimeofday - π Logging thread-safe actions
- Each philosopher is a thread
- Forks are represented using mutexes
- Philosophers must take two forks to eat
- The program must detect and handle:
- If a philosopher dies (time to die exceeded)
- When all have eaten enough times (optional)
- Safe multithreaded programming
- Real-time logic simulation
- Shared resource management
- Clean code structuring in low-level C
Hereβs a screenshot of the successful evaluation (score: 100%) from the 42 intranet.
