An introduction to threads, processes, and concurrency in C.
The Philosophers project explores multithreading, synchronization, and concurrent programming in C. It is based on the Dining Philosophers Problem, a classical concurrency challenge where philosophers alternate between eating, sleeping, and thinking. The goal is to implement a solution that avoids deadlocks and race conditions, ensuring all philosophers can eat without blocking each other.
- Two implementations:
- Mandatory: threads + mutexes
- Bonus: processes + semaphores
- Correct handling of:
- Shared memory
- Resource allocation
- Synchronization problems (deadlocks, race conditions)
- Simulation of philosophers’ life cycle: eating, sleeping, thinking
./philo (threads + mutexes)
./philo_bonus (processes + semaphores)
A thread is an independent sequence of execution within a process.
Threads share the same memory and resources, making them lightweight but requiring careful synchronization.
A race condition occurs when multiple threads/processes access or modify shared data simultaneously, leading to unpredictable outcomes.
Mutexes (locks) can prevent simultaneous access and ensure safe operations.
A deadlock happens when two or more threads wait indefinitely for resources locked by each other.
Proper resource ordering and synchronization design prevent deadlocks.
Clone the repository and compile:
git clone https://github.com/hanmpark/philosophers.git
cd philosophers
make./philo number_of_philosophers time_to_die time_to_eat time_to_slee [number_of_times_each_philosopher_must_eat]./philo_bonus number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

