Coder Social home page Coder Social logo

philosophers's Introduction

Dining Philosophers Simulation

This project includes two programs, one for the mandatory part and another for the bonus part, both simulating the classic Dining Philosophers problem. The programs are designed to comply with specific rules and requirements.

Mandatory Part - Philo

Description

The philo program implements the Dining Philosophers problem using threads and mutexes. Each philosopher is a thread, and the forks are protected by mutexes to prevent conflicts.

Build

To build the program, run the following command:

make

Run

To run the program, use the following command:

./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

Arguments

  • number_of_philosophers: The number of philosophers and forks.
  • time_to_die: Time in milliseconds. If a philosopher doesn’t start eating within this time after the last meal or simulation starts, they die.
  • time_to_eat: Time in milliseconds. The time it takes for a philosopher to eat.
  • time_to_sleep: Time in milliseconds. The time a philosopher spends sleeping.
  • number_of_times_each_philosopher_must_eat (optional): If specified, the simulation stops when all philosophers have eaten this many times. If not specified, the simulation stops when a philosopher dies.

Logs

The program generates logs in the specified format:

timestamp_in_ms X has taken a fork timestamp_in_ms X is eating timestamp_in_ms X is sleeping timestamp_in_ms X is thinking timestamp_in_ms X died

Bonus Part - philo_bonus

Description

The philo_bonus program is the bonus part of the project, implementing the Dining Philosophers problem with processes and semaphores. All forks are placed in the middle of the table, and each philosopher is a separate process.

Build

To build the program, run the following command:

make bonus

Run

To run the program, use the following command:

./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

Resources

philosophers's People

Contributors

ytijani 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.