Skip to content

This is a classic task that provides an understanding of Process synchronization, work with threads. The Dining Philosophers Problem.

Notifications You must be signed in to change notification settings

SavchenkoDV/Philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Dining Philosophers Problem

This repository contains the solution to the classical "Dining Philosophers Problem," which explores process synchronization and concurrency in C programming. The project aims to deepen understanding of thread management and resource sharing in a multi-threaded environment.

Description

The goal of the project was to implement a solution for the dining philosophers problem. Each philosopher is represented as a thread, and they can either be eating, thinking, or sleeping. To eat, a philosopher needs two forks, which are shared with others. The challenge was to avoid deadlock and ensure that all philosophers get a chance to eat.

Exercise:

• One or more philosophers are sitting at a round table doing one of three things: eating, thinking, or sleeping.
• While eating, they are not thinking or sleeping, while sleeping, they are not eating or thinking and of course, while thinking, they are not eating or sleeping.
• The philosophers sit at a circular table with a large bowl of spaghetti in the center.
• There are some forks on the table.
• As spaghetti is difficult to serve and eat with a single fork, it is assumed that a philosopher must eat with two forks, one for each hand.
• The philosophers must never be starving.
• Every philosopher needs to eat.
• Philosophers don’t speak with each other.
• Philosophers don’t know when another philosopher is about to die.
• Each time a philosopher has finished eating, he will drop his forks and start sleeping.
• When a philosopher is done sleeping, he will start thinking.
• The simulation stops when a philosopher dies.

Compiling's commands:

  • make - compiling
  • make clean - clean *.o
  • make fcleen - clean all
  • make re - recompiling

Arguments:

  1. number_of_philosophers
  2. time_to_die time_to_eat
  3. time_to_sleep
  4. number_of_times_each_philosopher_must_eat

Examples:

  • ./philo 5 800 200 200 - no one should die!
  • ./philo 5 800 200 200 7 - no one should die and the simulation should stop when all the philosopher has eaten atleast 7 times each.
  • ./philo 4 410 200 200 - no one should die!
  • ./philo 4 310 200 100 - a philosopher should die!

Attention!

  • Do not test with more than 200 philosophers
  • Do not test with time_to_die or time_to_eat or time_to_sleep under 60 ms - Test with 1 800 200 200, the philosopher should not eat and should die!

About

This is a classic task that provides an understanding of Process synchronization, work with threads. The Dining Philosophers Problem.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published