{"id":20383595,"url":"https://github.com/ygor-sena/42cursus-philosophers","last_synced_at":"2026-06-08T10:31:36.588Z","repository":{"id":68485564,"uuid":"592733677","full_name":"ygor-sena/42cursus-philosophers","owner":"ygor-sena","description":"The ninth project of 42's curriculum asks students to solve the famous Dijkstra's synchronization problem. This is a introduction to threads, mutexes and semaphores.","archived":false,"fork":false,"pushed_at":"2023-06-20T14:30:38.000Z","size":100,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-18T22:32:49.586Z","etag":null,"topics":["42","42cursus","42saopaulo","42school","42sp","ansi-c","c","ecole42","mutex","philosophers","philosophers-dinner-problem","philosophers42","semaphore","thread"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ygor-sena.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-01-24T12:20:11.000Z","updated_at":"2025-12-25T15:32:53.000Z","dependencies_parsed_at":"2023-07-25T17:32:12.721Z","dependency_job_id":null,"html_url":"https://github.com/ygor-sena/42cursus-philosophers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ygor-sena/42cursus-philosophers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygor-sena%2F42cursus-philosophers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygor-sena%2F42cursus-philosophers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygor-sena%2F42cursus-philosophers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygor-sena%2F42cursus-philosophers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ygor-sena","download_url":"https://codeload.github.com/ygor-sena/42cursus-philosophers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygor-sena%2F42cursus-philosophers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34059153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","42cursus","42saopaulo","42school","42sp","ansi-c","c","ecole42","mutex","philosophers","philosophers-dinner-problem","philosophers42","semaphore","thread"],"created_at":"2024-11-15T02:23:29.152Z","updated_at":"2026-06-08T10:31:36.563Z","avatar_url":"https://github.com/ygor-sena.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://user-images.githubusercontent.com/102881479/220914152-9fea3130-8edc-4f80-b936-be3c8c5e80e1.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/OS-Linux-blue\" alt=\"OS\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Language-C%20%7C%20C%2B%2B-blue.svg\" alt=\"Language\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Grade-125%2F100-brightgreen.svg\" alt=\"Grade\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Status-Completed-brightgreen.svg\" alt=\"Status\"\u003e\n\u003c/p\u003e\n\n## 📣 Introduction\n\nThe ninth project of 42's curriculum asks students to solve the famous Dijkstra's synchronization problem called *The Dining Philosophers Problem*. This is a introduction to multithreads, multiprocesses, mutexes and semaphores. \n\n## ⚒️ How to compile and run the project\n\n#### 1) Copy this repository to your local workstation\n\n```html\ngit clone git@github.com:ygor-sena/42cursus-philosophers.git\n```\n\n#### 2) Choose the mandatory or bonus folder to compile the project\n\nTo compile the mandatory project, execute the following command in your terminal:\n\n```html\ncd philo/ \u0026\u0026 make\n```\n\nOtherwise, if you want to compile the bonus version, execute:\n\n```html\ncd philo_bonus/ \u0026\u0026 make\n```\n\n#### 3) Run the program\n\nBoth the mandatory and bonus program take at least 5 arguments. The first parameter is the program's binary file and the last one is optional. Each of them stands for:\n\n| #2 | #3 | #4 | #5 | #6 (optional) |\n|:----|:----|:----|:----|:----|\n| 5 | 800 | 200 | 200 | 5 |\n| `number_of_philosophers` | `time_to_die` | `time_to_eat` | `time_to_sleep` | `number_of_times_each_must_eat` |\n\nSo, to start a dinning simulation where there are 5 philosophers that must eat 7 times each and the time to die, to eat and to sleep is 800, 200 and 200 respectively, we should execute the following command:\n\n```html\n./philo 5 800 200 200 7\n```\n\n#### 4) How to check for memory leaks and data race conditions\n\nRun the program with the valgrind's flags below to check for memory leaks:\n\n```\nvalgrind -q --leak-check=full --show-leak-kinds=all --track-origins=yes\n```\n\nAlso, run the program with valgrind's tools *DRD (Data Race Detector)* and *Helgrind* separately to search for data race conditions and typical syncronization problems such as deadlock:\n\n```\nvalgrind --tool=drd \n```\n\n```\nvalgrind --tool=helgrind \n```\n\n## ⚠️ Known issues\n\nThere are cases where a philosopher can die because the scheduler priorized some threads/processes instead of giving all of them the same priority. To avoid this, it is necessary to implement a function that always will make the hungriest philosopher dinner first. It is possible to implement this in the mandatory project according the rules of the subject. For the bonus project, we would need shared memory to share information between the child processes, but its use is not allowed by the subject.\n\n## 📖 References\n\n- General references:\n  - [Concorrência e Paralelismo (Parte 1) | Entendendo Back-End para Iniciantes ](https://www.youtube.com/watch?v=cx1ULv4wYxM) by [Fábio Akita](https://www.youtube.com/@Akitando).\n  - [Ansel Sermersheim: “Multithreading is the answer. What is the question? (part 1 of 2)](https://www.youtube.com/watch?v=GNw3RXr-VJk) by CppCon 2017.\n  - [Ansel Sermersheim: “Multithreading is the answer. What is the question? (part 2 of 2)](https://www.youtube.com/watch?v=sDLQWivf1-I) by CppCon 2017.\n  - [Unix Threads in C](https://www.youtube.com/watch?v=d9s_d28yJq0\u0026list=PLfqABt5AS4FmuQf70psXrsMLEDQXNkLq2) by [CodeVault](https://www.youtube.com/@CodeVault).\n\n- About the Dining Philosophers Problem:\n  - TANENBAUM, Andrew; BOS, Herbert. Modern Operating System. 4th edition. 2014.\n  - [The Dining Philosophers Problem With Ron Swanson](https://www.adit.io/posts/2013-05-11-The-Dining-Philosophers-Problem-With-Ron-Swanson.html) by [Aditya Bhargava](https://www.adit.io/index.html).\n\n- About threads and mutexes:\n  - [MYERS, Ethan. An Application of Pthreads and Mutexes](https://files.kipr.org/gcer/2009/proceedings/Myers_ApplicationPthreads.pdf) by Cedar Brook Academy.\n  - [POSIX Threads Programming](https://hpc-tutorials.llnl.gov/posix/) by [Lawrence Livermore National Laboratory](https://www.llnl.gov/).\n  - [Introduction to Parallel Computing Tutorial](https://hpc.llnl.gov/documentation/tutorials/introduction-parallel-computing-tutorial##Overview) by [Lawrence Livermore National Laboratory](https://www.llnl.gov/).\n  - [Race Condition vs. Data Race](https://blog.regehr.org/archives/490) by [Professor John Regehr](https://blog.regehr.org/).\n\n- About time conversion:\n  - [How to get the current time in milliseconds from C in Linux?](https://stackoverflow.com/questions/3756323/how-to-get-the-current-time-in-milliseconds-from-c-in-linux#17371925) by StackOverFlow\n  \n- About Helgrind and DRD (Data Race Detector):\n  - [Helgrind: a thread error detector](https://valgrind.org/docs/manual/hg-manual.html) by [Valgrind](https://valgrind.org/).\n  - [DRD: a thread error detector](https://valgrind.org/docs/manual/drd-manual.html) by [Valgrind](https://valgrind.org/).\n  \n- Interesting contents by fellow 42's students:\n  - [Web visualizer for Philosophers project](https://github.com/nafuka11/philosophers-visualizer) by [nafuka](https://github.com/nafuka11).\n  - [Visual summary of the Philosophers project](https://miro.com/app/board/o9J_l0AjIkc=/) made with Miro.\n  - [Acelera: Philosophers](https://rodsmade.notion.site/Acelera-Philosophers-a82a52edabe24ea4a382393fae6c4531) by [rodsmade](https://github.com/rodsmade).\n  - [Summary of the concepts of Philosophers project](https://www.notion.so/Philosophers-2b872948598e4f0cba91c66d8b5ba821) made with Notion.\n\n## 🫂 Acknowledgements\n\nI want to thank Marcelo Magalhães, also a student at [42SP](https://www.42sp.org.br/) for his support throughout the project when I needed. Please, check out his interesting projects at GitHub [here](https://github.com/magalhaesm).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fygor-sena%2F42cursus-philosophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fygor-sena%2F42cursus-philosophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fygor-sena%2F42cursus-philosophers/lists"}