Skip to content

herrera-diego/dining-philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dining Philosophers Problem license Build and Tests Code Grade

Implementation on Dining Philosophers problem on C++

Image

Problem Statement

A certain number of philosophers spend their lives alternating between thinking and eating. They are seated around a circular table. There is a chopstick placed between each pair of neighboring philosophers. Each philosopher has access to the chopsticks at her left and right. In order to eat, a philosopher must be in possession of both chopsticks. A philosopher may only pick up one chopstick at a time. Each philosopher attempts to pick up the left chopstick first and then the right chopstick. When done eating, a philosopher puts both chopsticks back down on the table and begins thinking. Since the philosophers are sharing chopsticks, it is not possible for all of them to be eating at the same time.

This was originally formulated in 1965 by Edsger Dijkstra as a student exam exercise.

Solution

Waiting State

  • The philosopher enters into a waiting state when neighbors are eating
  • When its neighbors are done, go for the chopsticks
  • Its neighbors can't enter into the waiting state if there is a neighbor already waiting

Tests

Tests are done using googletests

Releases

No releases published

Packages

No packages published