Giter Site home page Giter Site logo

philosophers's Introduction

Philosophers

Introduction to multi-threading in C

This project is a multithreaded simulation of the Dining Philosophers problem. The problem is a classic multi-process synchronization problem which was originally formulated in 1965 by Edsger Dijkstra as a student exam exercise.

Problem Statement

The problem consists of N philosophers sitting at a round table who do only three things: eat, think, and sleep. There is a bowl of spaghetti on the table, but philosophers need two forks to eat it. Each philosopher can only use the forks to their immediate right and left. The philosophers must find a solution that prevents them from starving.

Project Structure

The project is structured as follows:

  • philo/srcs/: This directory contains all the source code for the simulation that uses mutexes and threads.
  • philo_bonus/srcs/: This directory contains all the source code for the simulation that uses Semaphores and processes.
  • Makefile: This is used to compile the project.

How to Run

To run the project, follow these steps:

  1. Clone the repository
  2. Navigate into the cloned repository: cd <repository_directory>
  3. Compile the project: make

make will compile 2 executables, phil and phil_bonus, the first one is based on threads and mutexes, the latter uses semaphores and multi-process instead. both take the same arguments which are:

  1. NUMBER_OF_PHILOSOPHERS defines both how many philosophers there are as well as how many forks
  2. TIME_TO_DIE defines how much time (milliseconds) it takes for a philosopher to starve
  3. TIME_TO_EAT defines how much time (milliseconds) it takes for a philosopher to eat
  4. TIME_TO_SLEEP defines how much time (milliseconds) it takes for a philosopher to sleep
  5. {OPTIONAL} NUMBER_OF_MEALS defines how many meals must each philosopher eat before the simulation ends

example : ./philo 5 800 200 200 (in this example the simulation should not stop)

philosophers's People

Contributors

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