Giter VIP home page Giter VIP logo

forked_philosophers's Introduction

Forked_Philosophers

Overview

This is a C implementation of the Dining Philosophers problem, which is a classic example of a concurrency problem.
The problem involves a group of philosophers who are seated at a circular table with a fork between each pair of adjacent philosophers.
Each philosopher alternates between thinking and eating, and to eat, they must pick up the two forks on either side of them.
However, since there are only as many forks as there are philosophers, deadlock can occur if each philosopher picks up one fork and waits for the other.

Getting Started

This program simulates the behavior of the philosophers using threads and mutexes to avoid deadlock.
The program takes the following command-line arguments:
./philo num_philosophers time_to_die time_to_eat time_to_sleep [num_times_each_philosopher_must_eat]

num_philosophers: the number of philosophers at the table
time_to_die: the time in milliseconds after which a philosopher dies if they have not started eating
time_to_eat: the time in milliseconds it takes for a philosopher to eat
time_to_sleep: the time in milliseconds it takes for a philosopher to sleep
num_times_each_philosopher_must_eat (optional): the number of times each philosopher must eat before the simulation ends
The output of the program is a log of the actions of each philosopher, along with a timestamp in milliseconds.

Prerequisites

Installation

git clone [email protected]:Clivassy/Forked_Philosophers.git
cd Forked_Philosophers
make

Usage

To compile the program, run make. This will create an executable called philo.
To run the program, pass in the desired command-line arguments:
./philo 5 800 200 200 This will simulate a table with 5 philosophers, where each philosopher dies after 800 milliseconds of inactivity, it takes 200 milliseconds to eat and sleep.
Optionally, you can specify the number of times each philosopher must eat before the simulation ends:
./philo 5 800 200 200 3

This will end the simulation after each philosopher has eaten 3 times.

Useful Ressources

The Dining Philosophers Problem :
https://www.youtube.com/watch?v=FYUi-u7UWgw
https://www.youtube.com/watch?v=NbwbQQB7xNQ

Threads :
https://www.youtube.com/watch?v=o_GbRujGCnM
https://www.tutorialspoint.com/multithreading-in-c
https://www.geeksforgeeks.org/multithreading-c-2/

Datas Race:
https://www.youtube.com/watch?v=oq29KUy29iQ&list=PLfqABt5AS4FmuQf70psXrsMLEDQXNkLq2&index=4

forked_philosophers's People

Contributors

clivassy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.