š§ Philosophers ā Concurrency & Synchronization
The Philosophers project is a multithreading simulation of the classic Dining Philosophers Problem, implemented entirely in C.
Its core objective is to manage shared resources safely using mutexes, avoid deadlocks, and ensure correct timing, all following the strict performance and memory standards of the 42 Barcelona curriculum.
This project strengthened my understanding of concurrency, thread management, and the challenges of synchronizing shared state.
š Features
š¹ Multithreaded Simulation
Each philosopher runs in its own thread, performing:
- thinking
- eating
- sleeping
With precise timestamp logging.
š¹ Mutex-Based Fork Management
- Forks represented as mutexes
- Prevents race conditions
- Avoids simultaneous access to shared resources
š¹ Deadlock Prevention
Implements strategies to avoid circular waiting, ensuring philosophers can always progress.
š¹ Accurate Timing
Handles:
- time_to_die
- time_to_eat
- time_to_sleep
- microsecond-level accuracy
Using:
gettimeofday()- custom timing utilities
š¹ Robust Error Handling
- Validates arguments
- Gracefully handles invalid states
- Ensures threads exit cleanly
š§ What I Learned
- Multithreading with pthread
- Preventing deadlocks & starvation
- Designing safe concurrent systems
- Working with mutexes and shared resources
- Real-time coordination and timing logic
- Debugging race conditions and timing drifts
š Repository
š GitHub: https://github.com/zmetreveli/philo