{"id":21722970,"url":"https://github.com/akamlah/42-philosophers","last_synced_at":"2025-07-24T16:20:17.717Z","repository":{"id":123405809,"uuid":"447162398","full_name":"akamlah/42-Philosophers","owner":"akamlah","description":"Didactic project from Ecole-42. Two different solutions for an extended version of the famous 'Dining Philosophers' problem, the first as a multithreaded program ruled by mutexes, the second featuring multiple processes synchronised by semaphores.","archived":false,"fork":false,"pushed_at":"2022-10-24T10:24:12.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T22:19:26.180Z","etag":null,"topics":["c","multithreading","mutex-locks","mutexes","pthreads-api","semaphores","synchronization","unix-process"],"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/akamlah.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-01-12T09:54:22.000Z","updated_at":"2022-01-17T11:38:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"a692d536-7265-4a55-adf9-e56045a4f25d","html_url":"https://github.com/akamlah/42-Philosophers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/akamlah/42-Philosophers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamlah%2F42-Philosophers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamlah%2F42-Philosophers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamlah%2F42-Philosophers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamlah%2F42-Philosophers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akamlah","download_url":"https://codeload.github.com/akamlah/42-Philosophers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamlah%2F42-Philosophers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266870509,"owners_count":23998250,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"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":["c","multithreading","mutex-locks","mutexes","pthreads-api","semaphores","synchronization","unix-process"],"created_at":"2024-11-26T02:35:03.450Z","updated_at":"2025-07-24T16:20:17.686Z","avatar_url":"https://github.com/akamlah.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 42-Philosophers\nDidactic project from Ecole-42. Two different solutions for an extended version of the famous 'Dining Philosophers' problem, the first as a multithreaded program ruled by mutexes, the second featuring multiple processes synchronised by semaphores.\n\n## Building\n### Version 1 - posix threads\n\nat the root of the folder \"philo\":\n\n```\n$ make\n$ ./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]\n```\n\nThe last argument is optional. The maximum number of philosophers the program is tested for is 200 (i.e. 200 concurrent threads)\n\n### Version 2 - unix processes\n\nat the root of the folder \"philo_bonus\":\n\n```\n$ make\n$ ./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]\n```\n\nThe last argument is optional. The maximum number of philosophers the program is tested for is 200 (i.e. 200 concurrent processes)\n\n\n## The simulation\n\nOne or more philosophers sit at a round table.\nThere is a large bowl of spaghetti in the middle of the table.\nThe philosophers alternatively eat, think, or sleep.\nWhile they are eating, they are not thinking nor sleeping;\nwhile thinking, they are not eating nor sleeping;\nand, of course, while sleeping, they are not eating nor thinking.\nThere are also forks on the table. There are as many forks as philosophers.\nBecause serving and eating spaghetti with only one fork is very inconvenient, a\nphilosopher takes their right and their left forks to eat, one in each hand.\nWhen a philosopher has finished eating, they put their forks back on the table and\nstart sleeping. Once awake, they start thinking again. The simulation stops when\na philosopher dies of starvation.\nEvery philosopher needs to eat and should never starve.\nPhilosophers don’t speak with each other.\nPhilosophers don’t know if another philosopher is about to die.\n\nThe user gets a log printed on the terminal that informs whenever a philosopher has taken one of the following actions:\n* taking a fork\n* started eating\n* started thining\n* started sleeping\n* died\n\nPreceeded by a timestamp corresponding to the elapsed milliseconds from the start of the simulation. The main goal in this program was to optimize it in a way that as little delay as possible is accumulated, so that even for large numbers of threads/processes, if the parameters would ensure that the simulation runs infinitely (i.e. time to eat shorter that time to die for example), the implementation actually does run as long as possible, and is stopped only by system limitations.\nAlso another key point is the management of shared memory resources, and avoiding race conditions between threads.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamlah%2F42-philosophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakamlah%2F42-philosophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamlah%2F42-philosophers/lists"}