Skip to content

dmitrijslasko/42_philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

113 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philosophers, the concurrency project (School 42 project)

A classic problem in concurrency and multithreading, inspired by Edsger Dijkstra's Dining Philosophers problem. The project is designed to learn about thread synchronization, race conditions, mutexes, and deadlocks.

Philosophers Project

Problem description N philosophers are sitting around a circular table. Each philosopher has only one fork on their left and one on their right. There are exactly N forks for N philosophers.

Each philosopher follows a simple routine:

  1. Think 🤔
  2. Pick up two forks (one on the left, one on the right) to eat 🍽️
  3. Eat for a while 😋
  4. Put the forks down and go back to thinking 🔄

The challenge arises because if all philosophers pick up one fork at the same time, they will deadlock (waiting forever for the second fork).

Goal of the Project Mandatory part Use C language, implement a simulation of this problem using threads (POSIX threads, pthread library). No philosopher starves (i.e., they eventually eat). The program avoids deadlocks. The output logs each philosopher’s actions (thinking, eating, sleeping). This is done by using mutexes or other synchronization techniques to prevent race conditions.

Bonus part part To be added

Common Issues & Debugging

  1. Race conditions: If multiple threads modify shared data without proper locking.
  2. Deadlocks: If all philosophers pick up one fork and wait for the second.
  3. Starvation: If some philosophers get to eat repeatedly while others never do.

Score:

✅ TBA (with bonus)

Installation and launch 🚀

TBA 1. Clone the repo:

git clone https://github.com/dmitrijslasko/42_philosophers.git

2. Go into the folder:

Mandatory part: cd philosophers42/philo
Bonus part:	cd philosophers42/philo_bonus

3. Build the program:

make

4. Launch the program with your parameters, e.g.:

./philo 10 800 200 200 10

Implemented functionality 🤖

  1. Debug mode. Compile with:
make debug

MORE TO BE ADDED

Customizable parameters 🕹️

TBA

Known issues 🚨

TBA

Reading list 📚

TBA

Inspirations 💡

TBA

Questions? 🤔

Feel free to contact me: Slack: @dmlasko E-mail: dmitrijs.lasko@gmail.com Telegram: @lalamoose

About

A 42 project written in C that explores multithreading and synchronization using mutexes and processes. It simulates philosophers sitting around a table, eating, thinking, and sleeping while avoiding deadlocks and race conditions through precise thread management and timing control.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors