Skip to content

hanmpark/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philosophers

An introduction to threads, processes, and concurrency in C.


Repository created at Repository code size Mostly used language

📖 Description

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.

🛠️ Features

  • 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

🧩 Code Structure

./philo (threads + mutexes)

philo structure

./philo_bonus (processes + semaphores)

philo_bonus structure

🧠 Key Concepts

Threads

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.

Race Conditions 🏎

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.

Deadlocks 🔒

A deadlock happens when two or more threads wait indefinitely for resources locked by each other.
Proper resource ordering and synchronization design prevent deadlocks.

📦 Installation

Clone the repository and compile:

git clone https://github.com/hanmpark/philosophers.git
cd philosophers
make

🚀 Usage

Mandatory (threads + mutexes)

./philo number_of_philosophers time_to_die time_to_eat time_to_slee [number_of_times_each_philosopher_must_eat]

Bonus (processes + semaphores)

./philo_bonus number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

👤 Authors

About

Philosophers Dining Problem with threads / semaphores

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published