{"id":21933174,"url":"https://github.com/link-wolf/philosophers","last_synced_at":"2026-04-27T12:38:51.726Z","repository":{"id":47124247,"uuid":"473217286","full_name":"Link-Wolf/Philosophers","owner":"Link-Wolf","description":"42 project - Simultation of the Philosophers problem, with C-threads and mutex","archived":false,"fork":false,"pushed_at":"2024-09-30T13:14:15.000Z","size":303,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-27T12:49:41.926Z","etag":null,"topics":["42","42born2code","42school","c","macos","simulation"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Link-Wolf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-23T14:11:01.000Z","updated_at":"2024-09-30T13:14:18.000Z","dependencies_parsed_at":"2025-01-27T12:54:32.857Z","dependency_job_id":null,"html_url":"https://github.com/Link-Wolf/Philosophers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Link-Wolf%2FPhilosophers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Link-Wolf%2FPhilosophers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Link-Wolf%2FPhilosophers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Link-Wolf%2FPhilosophers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Link-Wolf","download_url":"https://codeload.github.com/Link-Wolf/Philosophers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244960985,"owners_count":20538911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42","42born2code","42school","c","macos","simulation"],"created_at":"2024-11-29T00:08:44.034Z","updated_at":"2026-04-27T12:38:46.701Z","avatar_url":"https://github.com/Link-Wolf.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv id=\"top\"\u003e\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\t\u003ca href=\"https://github.com/Link-Wolf/Philosophers\" title=\"Go to GitHub repo\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?label=Link-Wolf\u0026message=Philosophers\u0026color=blue\u0026logo=github\u0026style=for-the-badge\" alt=\"Link-Wolf - Philosophers\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://\"\u003e\u003cimg src=\"https://img.shields.io/badge/42_grade-100_%2F_100-brightgreen?style=for-the-badge\" alt=\"42 grade - 125 / 100\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://\"\u003e\u003cimg src=\"https://img.shields.io/badge/Year-2022-ffad9b?style=for-the-badge\" alt=\"Year - 2022\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/Link-Wolf/Philosophers/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/Link-Wolf/Philosophers?style=for-the-badge\u0026color=yellow\" alt=\"stars - Philosophers\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/Link-Wolf/Philosophers/network/members\"\u003e\u003cimg src=\"https://img.shields.io/github/forks/Link-Wolf/Philosophers?style=for-the-badge\u0026color=lightgray\" alt=\"forks - Philosophers\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/Link-Wolf/Philosophers/issues\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/Link-Wolf/Philosophers?style=for-the-badge\u0026color=orange\" alt=\"issues - Philosophers\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://www.apple.com/macos/\" title=\"Go to Apple homepage\"\u003e\u003cimg src=\"https://img.shields.io/badge/OS-macOS-blue?logo=apple\u0026logoColor=white\u0026style=for-the-badge\u0026color=9cf\" alt=\"OS - macOS\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca\u003e\n    \u003cimg src=\"https://www.42mulhouse.fr/wp-content/uploads/2022/06/logo-42-Mulhouse-white.svg\" alt=\"Logo\" width=\"192\" height=\"80\"\u003e\n  \u003c/a\u003e\n\n  \u003ch3 align=\"center\"\u003ePhilosophers\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n\t  \u003cem\u003eI’ve never thought philosophy would be so deadly.\u003c/em\u003e\u003cbr/\u003e\n\tLearn the basics of threading a process, how to make threads, and discover the mutex\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/Link-Wolf/Philosophers/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/Link-Wolf/Philosophers/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\n      \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#prerequisites\"\u003ePrerequisites\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#roadmap\"\u003eRoadmap\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n\n## About The Project\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca\u003e\n    \u003cimg src=\"assets/phlo_illu.png\" alt=\"FdF header\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\u003c/br\u003e\n\nThe philosophers' problem is the classical problem of synchronization which says that `n` philosophers are sitting around a circular table and their job is to think and eat in turn.\u003c/br\u003e\nA bowl of noodles is placed at the center of the table along with `n` forks between each philosopher\u003c/br\u003e\nTo eat a philosopher needs both their right and left forks. A philosopher can only eat if both their immediate left and immediate right forks are available\n\u003c/br\u003eIn case either of their immediate left or immediate right fork is not available then they put down their other fork and start thinking again.\nIf the philosopher can eat, they do then they'll sleep before thinking again\n\nThe goal of the project is to simulate this problem by using C `threads`, and with custom parameters\n\n-   `number_of_philosophers` : the number of philosophers and also the number of forks\n-   `time_to_die` : if a philosopher doesn’t start eating `time_to_die` milliseconds after starting his last meal or the beginning of the simulation, he dies\n-   `time_to_eat` : The time (in milliseconds) it takes for a philosopher to eat. During that time he will need to keep the two forks\n-   `time_to_sleep` : The time (in milliseconds) the philosopher will spend sleeping\n-   **[Optional]** `number_of_times_each_philosopher_must_eat` : if every philosopher eat at least `number_of_times_each_philosopher_must_eat` times, the simulation will stop. If not specified, the simulation will stop only at the death of a philosopher\n\nEach philosopher should be a `thread`, to avoid philosophers duplicating forks we have to protect the forks state with a\n`mutex` for each of them and philosophers don’t speak with each other.\nPhilosophers should avoid dying, so the program should organize each philosopher time, and print any change of status of a philosopher as :\n\n```\n  [timestamp_in_ms] X ([has taken a fork] / [is eating] / [is sleeping] / [is thinking] / [died])\n```\n\n### Bonus features\n\nIn the bonus version, all the forks are in the middle of the table\u003c/br\u003e\nThey have no states in memory but the number of available forks is represented by\na `semaphore`\u003c/br\u003e\nAnd each philosopher should be a process and the main process should not be a philosopher\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- GETTING STARTED --\u003e\n\n## Getting Started\n\nBecause it's a simple C program, there isn't much to say here\n\n### Prerequisites\n\nHaving a C compiler like cc, gcc or clang\n\n### Installation\n\n1. Clone the repo\n    ```sh\n    git clone https://github.com/Link-Wolf/Philosophers.git\n    ```\n2. Compile Philosophers\n    ```sh\n    cd Philosophers/philo; make\n    ```\n3. Execute the program with parameters described \u003ca href=\"#about-the-project\"\u003ehere\u003c/a\u003e and see how it works\n\n    ```sh\n    ./philo 6 800 400 200\n    ```\n\n    _it should run forever_\n\n    Or stop the program with `number_of_times_each_philosopher_must_eat`\n\n    ```sh\n    ./philo 6 800 400 200 15\n    ```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- USAGE EXAMPLES --\u003e\n\n## Usage\n\nTest this Philosophers with the parameters you want, with or without a stopper !\n\n#### Example\n\n```sh\n   ./philo 3 800 400 200 3\n```\n\n#### Output\n\n```\n\t0 0 is thinking\n\t0 0 has taken a fork\n\t0 0 has taken a fork\n\t0 0 is eating\n\t0 1 is thinking\n\t0 2 is thinking\n\t400 0 is sleeping\n\t400 1 has taken a fork\n\t400 1 has taken a fork\n\t400 1 is eating\n\t600 0 is thinking\n\t800 1 is sleeping\n\t800 2 has taken a fork\n\t800 2 has taken a fork\n\t800 2 is eating\n\t1000 1 is thinking\n\t1200 2 is sleeping\n\t1200 0 has taken a fork\n\t1200 0 has taken a fork\n\t1200 0 is eating\n\t1400 2 is thinking\n\t1600 0 is sleeping\n\t1600 1 has taken a fork\n\t1600 1 has taken a fork\n\t1600 1 is eating\n\t1800 0 is thinking\n\t2000 1 is sleeping\n\t2000 2 has taken a fork\n\t2000 2 has taken a fork\n\t2000 2 is eating\n\t2200 1 is thinking\n\t2400 2 is sleeping\n\t2400 0 has taken a fork\n\t2400 0 has taken a fork\n\t2400 0 is eating\n\t2600 2 is thinking\n\t2800 0 is sleeping\n\t2800 1 has taken a fork\n\t2800 1 has taken a fork\n\t2800 1 is eating\n\t3000 0 is thinking\n\t3200 1 is sleeping\n\t3200 2 has taken a fork\n\t3200 2 has taken a fork\n\t3200 2 is eating\n```\n\n#### Example where a philosopher die\n\n```sh\n   ./philo 3 500 400 200\n```\n\n#### Output\n\n```\n\t0 0 is thinking\n\t0 2 is thinking\n\t0 0 has taken a fork\n\t0 0 has taken a fork\n\t0 0 is eating\n\t0 1 is thinking\n\t400 0 is sleeping\n\t400 1 has taken a fork\n\t400 1 has taken a fork\n\t400 1 is eating\n\t500 2 died\n```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- ROADMAP --\u003e\n\n## Roadmap\n\n-   [ ] Add the bonuses (surely never)\n\nSee the [open issues](https://github.com/Link-Wolf/Philosophers/issues) for a full list of proposed features (and known issues).\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- CONTRIBUTING --\u003e\n\n## Contributing\n\nIf you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag \"enhancement\".\nDon't forget to give the project a star! Thanks again!\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flink-wolf%2Fphilosophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flink-wolf%2Fphilosophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flink-wolf%2Fphilosophers/lists"}