Skip to content

Eat, Sleep, Spaghetti, repeat. This project is about learning how threads work by precisely timing a group of philosophers on when to pick up forks and eat spaghetti without dying from hunger.

Notifications You must be signed in to change notification settings

AtibQur/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philosophers🍝🍴

Score

Description Philosophers

This projects involves making use of threads and mutexes. By precisely timing a group of philosphers on when to pick a fork and spaghetti without dying from hunger.

To succeed this assignement:
  • One or more philosophers sit at a round table. There is a large bowl of spaghetti in the middle of the table.
  • The philosophers alternatively eat, think, or sleep. While they are eating, they are not thinking nor sleeping; while thinking, they are not eating nor sleeping; and, of course, while sleeping, they are not eating nor thinking.
  • There are also forks on the table. There are as many forks as philosophers.
  • • There are also forks on the table. There are as many forks as philosophers.
  • When a philosopher has finished eating, they put their forks back on the table and start sleeping. Once awake, they start thinking again. The simulation stops when a philosopher dies of starvation.
  • Every philosopher needs to eat and should never starve.
  • Philosophers don’t speak with each other.
  • Philosophers don’t know if another philosopher is about to die.
  • No need to say that philosophers should avoid dying!
  • Installation ⚙️

    *To build the programm there is only a few steps: First of all, you can download the repository through the following steps in any shell of your preference:*
    [email protected]:AtibQur/philosophers.git
    cd philosophers
    make
    
    These commands will compile everything and a executable "philo" should be created.

    Usage 🛠️

    To compile the program, run the following command:

    cd philosophers && make
    
    After creating the executable, the function is ready for use. This function only takes integers and will return errors if a non numeric character is used.
    The program takes 4 or 5 arguments:
    1: ./philo
    2: amount of philosopher
    3: time to eat
    4: time to sleep
    5: amount of meals to eat (optional)

    ./philo 3 410 200 200 5 --> will fail
    

    Score

    ./philo 4 410 200 200 5 --> will run till amount of times to eat is true
    

    Score

    3rd party helpers

    educative
    https://www.educative.io/answers/how-to-create-a-simple-thread-in-c
    MichelleJiam tester
    https://github.com/MichelleJiam/LazyPhilosophersTester/tree/9819a70a3f6bab412d6615d26d625d648fa3695a
    Dining philosophers problem wikipedia
    https://en.wikipedia.org/wiki/Dining_philosophers_problem
    Jacob Sorber
    How to create and join threads in C (pthreads):
    https://www.youtube.com/watch?v=uA8X5zNOGw8&list=PL9IEJIKnBJjFZxuqyJ9JqVYmuFZHr7CFM&index=1
    How to pass arguments to and get results from threads. (pthread_create, pthread_join):
    https://www.youtube.com/watch?v=It0OFCbbTJE&list=PL9IEJIKnBJjFZxuqyJ9JqVYmuFZHr7CFM&index=2
    How to pass arguments to and get results from threads. (pthread_create, pthread_join):
    https://www.youtube.com/watch?v=9axu8CUvOKY&list=PL9IEJIKnBJjFZxuqyJ9JqVYmuFZHr7CFM&index=3

    About

    Eat, Sleep, Spaghetti, repeat. This project is about learning how threads work by precisely timing a group of philosophers on when to pick up forks and eat spaghetti without dying from hunger.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published