Skip to content

miketaonjo/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philosophers – Concurrent Programming with Threads & Mutexes in C

Philosophers is a concurrent programming project based on Edsger Dijkstra’s famous Dining Philosophers problem. The objective is to design a synchronization algorithm using threads and mutexes to prevent race conditions, starvation, and deadlocks under strict timing constraints. The project focuses on multithreading, shared resource protection, precise timing control, and lifecycle management of concurrent entities

Overview

  • Language: C
  • Concurrency Model: POSIX threads (pthreads)
  • Synchronization: Mutexes
  • Problem Type: Resource contention simulation
  • Constraints: No philosopher communication
  • Synchronization: Shared resource locking
  • Time Management: Millisecond-precision timing
  • Focus: Deadlock avoidance, starvation prevention, race condition control

Problem description

We must create an algorithm that keeps the philosophers alive as far as possible. The programs must take several parameters:

number_of_philosophers: the number of philosophers around the table
time_to_die: a number representing the time in milliseconds a philosopher has to live after a meal. If a philosopher hasn’t started eating time_to_die milliseconds after the beginning of his last meal or the beginning of the simulation, he will die.
time_to_eat: a number representing the time in milliseconds a philosopher takes to finish his meal. During that time, the philosopher keeps his two forks in hand.
time_to_sleep: the time in milliseconds that a philosopher spends sleeping.
number_of_times_each_philosopher_must_eat: an optional argument that allows the program to stop if all the philosophers have eaten at least that many times. If this argument is not specified, the simulation carries on unless a philosopher dies.

Installation

git clone <repository_url>
cd philosophers/philo
make

Execution

./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philo_must_eat]

Exemples

./philo 4 800 200 200

About

Concurrent programming project in C exploring synchronization with threads, mutexes, processes and semaphores through the Dining Philosophers problem.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors