Skip to content

The famous "Dining Philosophers" problem coded in C using two methods. The first one using threads and mutexes, and a second one using processes and semaphore.

Notifications You must be signed in to change notification settings

lassachraf/42_Philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Philosophers Project

Introduction

The "Philosophers" project is part of the 42 Network's Common Core curriculum. It revolves around the famous "Dining Philosophers" problem, which is a classic synchronization issue in computer science used to illustrate the challenges of resource sharing and concurrency.

Project Overview

Objective:

The project aims to train students in multi-threading and multi-process programming using mutexes and semaphores. It involves implementing simulations of the Dining Philosophers problem with different synchronization techniques.

Key Concepts:

Dining Philosophers Problem:

  • Philosophers sit at a circular table with a bowl of spaghetti and a fork between each pair.
  • Each philosopher must alternate between eating, thinking, and sleeping.
  • To eat, a philosopher needs two forks, which introduces a challenge to avoid deadlock and ensure no philosopher starves.

Project Variants:

  • Mandatory part : Uses multi-threading with mutexes.
  • Bonus part : Uses multi-processing with semaphores.

Rules and Requirements:

  • The simulation must ensure that no philosopher starves.
  • Philosophers do not communicate with each other.
  • The simulation stops when a philosopher dies of starvation.
  • The project must be coded in C, adhering to the 42 Norm, which includes strict coding standards and no memory leaks or crashes.

Compilation and Execution

git clone https://github.com/lassachraf/42_Philosophers.git
cd 42_Philosophers
  • For mandatory :
make
./philo nb_philo time_to_die time_to_eat time_to_sleep max_meals
  • For bonus :
make bonus
./philo_bonus nb_philo time_to_die time_to_eat time_to_sleep max_meals
  • nb_philo : Number of philosophers.
  • time_to_die : Time to die in milliseconds.
  • time_to_eat : Time to eat in milliseconds.
  • time_to_sleep : Time to sleep in milliseconds.
  • max_meals : Number of times each philosopher must eat (Optional parameter).

Learning Outcomes

  • Managing concurrency and synchronization in software development.
  • Using mutexes and semaphores to handle shared resources.
  • Optimizing C code for performance, which is critical for real-time systems.

Project score:

About

The famous "Dining Philosophers" problem coded in C using two methods. The first one using threads and mutexes, and a second one using processes and semaphore.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages