Skip to content

joao613/Philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philosophers

This project simulates the dining philosophers problem using threads and mutexes.

The dining philosophers problem is a classic synchronization problem in computer science, which involves a group of philosophers sitting around a table with a bowl of food and forks. Each philosopher alternates between thinking and eating. However, there are only a limited number of forks available for the philosophers to share. The challenge is to design an algorithm that allows the philosophers to dine peacefully without getting into a deadlock or starvation situation.

project provides a solution to this problem by creating a simulation of the dining philosophers scenario. It utilizes threads to represent each philosopher and mutexes to represent the forks. The program ensures that the philosophers follow a set of rules to avoid deadlocks and provide fairness in resource allocation.

Compilation

To build the project, follow these steps:

  1. Build the project using the provided Makefile:

    make
    

This will compile the source files and generate an executable named philo.

Run

Once you have built the project, you can run it with the following command:

./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philosopher_must_eat]
  • <number_of_philosophers>: The number of philosophers sitting around the table.
  • <time_to_die>: The maximum time in milliseconds that a philosopher can survive without eating.
  • <time_to_eat>: The time in milliseconds it takes for a philosopher to finish eating.
  • <time_to_sleep>: The time in milliseconds the philosopher spends sleeping after eating.
  • [number_of_times_each_philosopher_must_eat] (optional): The number of times each philosopher must eat before the simulation ends. If not provided, the simulation will continue indefinitely.

About

This project aims to teach concurrent programming, focusing on multithreading and multiprocessing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors