{"id":20442838,"url":"https://github.com/simon-zerisenay/42_philosophers","last_synced_at":"2026-06-08T05:31:34.722Z","repository":{"id":169821644,"uuid":"645886319","full_name":"simon-zerisenay/42_Philosophers","owner":"simon-zerisenay","description":"42 Philosophers: Philosophers is a project that involves solving the dining philosophers problem using threads and synchronization. The goal is to implement a solution where multiple philosophers can share a limited number of resources (such as forks) without encountering deadlocks or starvation.","archived":false,"fork":false,"pushed_at":"2024-05-01T05:21:31.000Z","size":87,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T08:16:58.214Z","etag":null,"topics":["42","42abudhabi","42philosophers","42projects","c","cprogramming","ecole42","mutex","philosophers","threads"],"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/simon-zerisenay.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":"2023-05-26T17:10:14.000Z","updated_at":"2025-01-14T23:34:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"badca097-9f00-4539-8dd3-0750f785f5e4","html_url":"https://github.com/simon-zerisenay/42_Philosophers","commit_stats":null,"previous_names":["simon-zerisenay/42_philosophers"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/simon-zerisenay/42_Philosophers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-zerisenay%2F42_Philosophers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-zerisenay%2F42_Philosophers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-zerisenay%2F42_Philosophers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-zerisenay%2F42_Philosophers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simon-zerisenay","download_url":"https://codeload.github.com/simon-zerisenay/42_Philosophers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-zerisenay%2F42_Philosophers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34050225,"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","42abudhabi","42philosophers","42projects","c","cprogramming","ecole42","mutex","philosophers","threads"],"created_at":"2024-11-15T09:43:14.057Z","updated_at":"2026-06-08T05:31:34.708Z","avatar_url":"https://github.com/simon-zerisenay.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":" \n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003eDinning Philosophers\u003c/h1\u003e\n\t\n\u003ca href=\"https://github.com/simon-zerisenay/42_Philosophers\"\u003e![42 Badge](https://github.com/mcombeau/mcombeau/blob/main/42_badges/philosophersm.png)\u003c/a\u003e\n\n\u003c/div\u003e\n\u003clabel\u003e\n\t\u003ch2\u003e Score \u003c/h2\u003e\t\n\t\u003cimg alt=\"100\" style=\"width: 100px;height: 70px\" src=\"https://github.com/simon-zerisenay/simon-zerisenay/blob/main/100.png\"/\u003e\n\u003c/label\u003e \n\u003ch2\u003eIntroduction\u003c/h2\u003e\n\u003cp align=\"center\"\u003e\n\t\u003cimg alt=\"GitHub code size in bytes\" src=\"https://img.shields.io/github/languages/code-size/simon-zerisenay/42_Philosophers?color=lightblue\" /\u003e\n\t\u003cimg alt=\"Number of lines of code\" src=\"https://img.shields.io/tokei/lines/github/simon-zerisenay/42_Philosophers?color=critical\" /\u003e\n\t\u003cimg alt=\"Code language count\" src=\"https://img.shields.io/github/languages/count/simon-zerisenay/42_Philosophers?color=yellow\" /\u003e\n\t\u003cimg alt=\"GitHub top language\" src=\"https://img.shields.io/github/languages/top/simon-zerisenay/42_Philosophers?color=blue\" /\u003e \n\t\u003cimg alt=\"GitHub last commit\" src=\"https://img.shields.io/github/last-commit/simon-zerisenay/42_Philosophers?color=green\" /\u003e\n\u003c/p\u003e  \nWelcome to the Philosopher project! This project is part of the curriculum at 42 and focuses on solving the dining philosophers problem using threads and synchronization techniques. The dining philosophers problem is a classic synchronization problem in computer science that illustrates resource sharing and deadlock avoidance.\n \n\u003ch2\u003eObjective\u003c/h2\u003e  \nThe main objective of the Philosopher project is to design a program that simulates the dining philosophers problem, where a certain number of philosophers sit around a table with a shared set of forks. The philosophers alternate between thinking and eating, but to eat, they must pick up the two adjacent forks. The challenge is to ensure that each philosopher can successfully eat without causing a deadlock or starvation.   \n  \n\u003ch2\u003eFeatures\u003c/h2\u003e \n\u003ch3\u003eProgram Design\u003c/h3\u003e \nThe Philosopher project involves designing a program that simulates the dining philosophers problem. The key features of the program include:\n \n\u003ch3\u003ePhilosophers:\u003c/h3\u003e \nThe program represents philosophers as individual threads, each responsible for alternating between thinking and eating.\n\u003ch3\u003eForks:\u003c/h3\u003e \nThe forks are shared resources used by the philosophers to eat. Each philosopher needs two adjacent forks to eat. \n\u003ch3\u003eSynchronization:\u003c/h3\u003e \nThe program must implement synchronization mechanisms to ensure that the philosophers can access the forks without causing conflicts or deadlocks. Techniques such as mutexes, semaphores, or other synchronization primitives can be used.\n\u003ch2\u003e Dining Philosophers Problem\u003c/h2\u003e\nThe dining philosophers problem is a classic synchronization problem in computer science that highlights challenges related to resource sharing and deadlock avoidance. It is named after a scenario where a group of philosophers is seated around a table and alternates between thinking and eating. The philosophers share a set of forks placed between them on the table.\n\nThe problem arises when each philosopher requires two adjacent forks to eat. If a philosopher picks up one fork and waits for the adjacent fork to become available, it can lead to a deadlock situation. Deadlock occurs when each philosopher is holding one fork and waiting indefinitely for the adjacent fork, resulting in a deadlock where no philosopher can proceed.\n\nThe dining philosophers problem aims to find a solution that allows all philosophers to eat without deadlocks or starvation. Several strategies can be employed to address this problem:\n\n\u003ch3\u003eResource Sharing:\u003c/h3\u003e\nEach fork can be considered a shared resource, and philosophers must properly allocate and release forks to avoid conflicts. For example, philosophers can be assigned a unique identifier and required to pick up the lower-indexed fork first, minimizing the possibility of circular dependencies.\n\n\u003ch3\u003eDeadlock Avoidance:\u003c/h3\u003e\nImplementing a protocol to prevent deadlock is essential. One common approach is to use a limit on the number of philosophers allowed to pick up forks simultaneously. By limiting the number of philosophers, it ensures that at least one philosopher can eat without waiting indefinitely.\n\n\u003ch3\u003eSynchronization Mechanisms:\u003c/h3\u003e\nVarious synchronization techniques can be used to ensure proper resource sharing. Mutexes or semaphores can be employed to protect critical sections where philosophers access forks. These mechanisms help enforce mutual exclusion, allowing only one philosopher to hold a fork at a time.\n\n\u003ch3\u003eFairness:\u003c/h3\u003e\nEnsuring fairness is crucial to prevent starvation, where a philosopher is unable to eat due to other philosophers continuously acquiring the required forks. Techniques like a waiter or arbiter can be introduced to control access to the forks, ensuring that each philosopher gets a fair chance to eat.\n\nSolving the dining philosophers problem requires finding a balance between resource sharing, synchronization, and avoiding deadlocks or starvation. It is a fundamental problem in concurrent programming, highlighting the complexities of coordinating shared resources among multiple processes or threads.\n\nBy studying and implementing solutions to the dining philosophers problem, programmers gain insights into critical synchronization concepts and techniques that are essential in developing robust and efficient concurrent systems.\n\n\u003ch2\u003eInstallation and Usage\u003c/h2\u003e\nTo install and run the Philosopher project, follow these steps:\n\nClone the project repository: \n\n\t\t\t\tgit clone https://github.com/your_username/42-philosopher.git\nNavigate to the project directory: \n\t\t\t\t\n\t\t\t\t\tcd 42-philosopher\nCompile the project using the provided Makefile: \n\n\t\t\t\t   \t\t make\nRun the program with the desired number of philosophers: \n\n\t./philo \u003cnumber_of_philosophers\u003e \u003ctime_to_die\u003e \u003ctime_to_eat\u003e \u003ctime_to_sleep\u003e [number_of_times_each_philosopher_must_eat]\nEnsure that you have the necessary libraries and dependencies installed on your system. The project's repository may provide further instructions on any additional requirements.\n\n\u003ch2\u003eTesting\u003c/h2\u003e\nTo test the Philosopher project and evaluate its functionality, follow these steps:\n\nRun the program with different configurations, including various numbers of philosophers and different time constraints.\nObserve the behavior of the philosophers and verify that they alternate between thinking and eating.\nMonitor the synchronization mechanisms to ensure that the philosophers share the forks properly and avoid deadlock.\nTest the program with edge cases, such as a single philosopher or a large number of philosophers, to validate its robustness and performance.\nMeasure the program's resource utilization and efficiency to ensure optimal performance.\nBy conducting thorough testing, you can ensure the correctness and effectiveness of your implementation of the dining philosophers problem.\n\u003cbr/\u003e\n\u003cbr/\u003e\nNote: The optional argument [number_of_times_each_philosopher_must_eat] allows you to specify a condition where each philosopher must eat a certain number of times before the program terminates.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon-zerisenay%2F42_philosophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimon-zerisenay%2F42_philosophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon-zerisenay%2F42_philosophers/lists"}