Skip to content

Dining philosophers problem. Mutexes and pthreads and semaphores galore

Notifications You must be signed in to change notification settings

acarlson99/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philosophers

7 philosophers are seated around a table

Between each pair of philosophers is one chopstick

A philosopher must hold two chopsticks to eat

He can:

  • eat - hold two chopsticks
  • rest - hold no chopsticks
  • think - hold one chopstick

After eating he must rest

After resting he can eat or think

Manage the allocation of resources so they all get a chance to eat

wikipedia

swanson

Dependencies

  • go 1.13
  • make
  • libpthread
  • libsdl2

Build

make

Usage

./philo_go	# run go version
./philo_c 5	# run c version with n philosophers

Algorithm

Go

Uses a semaphore to limit access to the table

At least one philosopher is always waiting to be seated, leaving everyone with enough utensils to eat

philo_c screenshot

C

Handles resource contention by giving the stick to the philosopher with a lower id

This makes sure everyone is not left with one chopstick, resulting in a deadlock

philo_c screenshot

About

Dining philosophers problem. Mutexes and pthreads and semaphores galore

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published