Skip to content

A simulation of the classic Dining Philosophers problem using threads and multithreading.

Notifications You must be signed in to change notification settings

olebol/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philosophers

This repository contains a program that simulates the classic Dining Philosophers problem. The objective of this project is to implement a program written solely in C without the use of global variables and completely abiding by 42 Network's Norme. This project is an introduction to threads and multithreading.

The Dining Philosophers problem involves a group of philosophers sitting around a circular table with a bowl of rice and a fork between each pair of adjacent philosophers. The philosophers alternate between thinking and eating, and they require two forks to eat their meal.

Features

  • Multithreading

Getting Started

Prerequisites

  • A Unix-like operating system such as Linux or macOS.
  • GCC compiler installed.

Installing and running

  1. Clone this repository:
git clone https://github.com/olebol/philosophers philosophers
  1. cd into the right directory
cd philosophers
  1. Run Make to compile the program
make COLOUR=0

or

make COLOUR=1
  1. Execute the program
./philo amount time_to_die time_to_eat time_to_sleep [times_philosopher_must_eat]

Arguments

  • amount: The number of philosophers and also the number of forks.
  • time_to_die: If a philosopher didn’t start eating time_to_die milliseconds since the beginning of their last meal or the beginning of the simulation, they die.
  • time_to_eat: The time it takes for a philosopher to eat. During that time, they will need to hold two forks.
  • time_to_sleep: The time a philosopher will spend sleeping.
  • times_philosopher_must_eat (optional argument): If all philosophers have eaten at least times_philosopher_must_eat times, the simulation stops. If not specified, the simulation stops when a philosopher dies.

About

A simulation of the classic Dining Philosophers problem using threads and multithreading.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published