{"id":18918623,"url":"https://github.com/hyxogen/philosophers","last_synced_at":"2025-06-20T12:02:58.287Z","repository":{"id":92512527,"uuid":"456402086","full_name":"Hyxogen/philosophers","owner":"Hyxogen","description":"A 42 common core project about philosophy and threads","archived":false,"fork":false,"pushed_at":"2022-11-12T07:13:05.000Z","size":618,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"2.0","last_synced_at":"2025-06-01T08:03:07.388Z","etag":null,"topics":["42projects","c","dining-philosophers-problem","mutexes","pthreads","semaphores"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hyxogen.png","metadata":{"files":{"readme":"README","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":"2022-02-07T07:32:46.000Z","updated_at":"2022-11-12T07:13:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"71c567e6-22d5-4a81-ba99-6c921bba94a6","html_url":"https://github.com/Hyxogen/philosophers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Hyxogen/philosophers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyxogen%2Fphilosophers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyxogen%2Fphilosophers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyxogen%2Fphilosophers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyxogen%2Fphilosophers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hyxogen","download_url":"https://codeload.github.com/Hyxogen/philosophers/tar.gz/refs/heads/2.0","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyxogen%2Fphilosophers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260941835,"owners_count":23086332,"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":["42projects","c","dining-philosophers-problem","mutexes","pthreads","semaphores"],"created_at":"2024-11-08T10:32:48.255Z","updated_at":"2025-06-20T12:02:53.269Z","avatar_url":"https://github.com/Hyxogen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"philosophers\n============\nPhilosophers is a 42 core curriculum project for learning about\nthreads, mutexes and semaphores by solving a slightly modified version\nof the dining philosophers problem\n(https://en.wikipedia.org/wiki/Dining_philosophers_problem).\n\nOverview\n============\nx One or more philosophers sit at a round table.\n  There is a large bowl of spaghetti in the middle of the table.\nx The philosophers alternatively eat, think, or sleep.  While they are\n  eating, they are not thinking nor sleeping; while thinking, they are\n  not eating nor sleeping; and, of course, while sleeping, they are\n  not eating nor thinking.\nx There are also forks on the table. There are as many forks as\n  philosophers\nx Because serving and eating spaghetti with only one fork is very\n  inconvenient, a philosopher takes their right and their left forks to\n  eat, one in each hand.\nx When a philosopher has finished eating, they put their forks back on\n  the table and start sleeping. Once awake, they start thinking\n  again. The simulation stops when a philosopher dies of starvation.\nx Every philosopher needs to eat and should never starve.\nx Philosophers don’t speak with each other.\nx Philosophers don’t know if another philosopher is about to die.\nx No need to say that philosophers should avoid dying!\n\nGlobal rules\n============\nx Global variables are forbidden\nx The program must take the following arguments:\n  number_of_philosophers time_to_die time_to_eat time_to_sleep\n  [number_of_times_each_philosopher_must_eat]\n  x number_of_philosophers: the number of philosophers and also the\n    number of forks\n  x time_to_die (in milliseconds): if a philosopher didn't start eating\n    time_to_die milliseconds since the beginning of their last meal, or\n    the beginning of the simulation, the philosopher dies\n  x time_to_eat (in milliseconds): the time it takes for a philosopher\n    to eat. During this time, the philosopher will need to hold two\n    forks\n  x time_to_sleep (in milliseconds): the time a philosopher will spend\n    sleeping\n  x number_of_times_each_philosopher_must_eat (optional): if all\n    philosophers have eaten at least\n    number_of_times_each_philosopher_must_eat times, then the\n    simulation stops. If not specified, the simulation stops when a\n    philosopher dies\nx Each philosopher has a number ranged from 1 to\n  number_of_philosophers\nx Philosopher number 1 sits next to philosopher\n  number_of_philosophers. Any other philosopher number N sits between\n  philosopher number N - 1 and philosopher number N + 1\nx Any state change of a philosopher must be formatted as follows:\n  x timestamp_in_ms X has taken a fork\n  x timestamp_in_ms X is eating\n  x timestamp_in_ms X is sleeping\n  x timestamp_in_ms X is thinking\n  x timestamp_in_ms X died\n  (with timestamp_in_ms replaced by the current timestamp in\n  milliseconds and X with the philosopher number)\nx A displayed state message should not be mixed up with another\n  message.\nx A message announcing a philosopher died should be displayed within\n  10 ms after the actual death of the philosopher\nx Philosophers should avoid dying\n\nMandatory part rules\n============\nx Each philosophers should be a thread\nx There is one fork between each pair of philosophers, Therefore, if\n  there are several philosophers, each philosopher has a fork on their\n  left side and a fore on their right side. If there is only one\n  philosopher, there should be only one fork on the table\nx To prevent philosophers from duplicating forks, you should protect\n  the forks state with a mutex for each of them\n\nAllowed external functions:\nmemset, printf, malloc, free, write, usleep, gettimeofday,\npthread_create, pthread_detach, pthread_join, pthread_mutex_init,\npthread_mutex_destroy, pthread_mutex_lock, pthread_mutex_unlock\n\nMy mandatory solution\n============\nx All philosophers always try to take both forks, and hold them for as\n  long as is needed (this means that they won't drop a fork if the\n  other side isn't available)\nx All uneven philosophers will sleep `eat_time` at the beginning of\n  the project\n\nBonus part rules\n============\nx All forks are put in the middle of the table\nx They have no states in memory but the number of available forks is\n  represented by a semaphore\nx Each philosopher should be a process, but the main process should\n  not be a philosopher\n\nAllowed external functions:\nmemset, printf, malloc, free, write, fork, kill, exit, pthread_create,\npthread_detach, pthread_join, usleep, gettimeofday, waitpid, sem_open,\nsem_close, sem_post, sem_wait, sem_unlink\n\nMy bonus solution\n============\nFor the bonus I just let all the philosophers loose and try to take\nforks as they see fit as that seems to be the best solution when the\npile of forks is in the middle.\n\nSpecial Thanks\n============\nSpecial Thanks to dnoom and mjoosten for pointing out that philosopher\nids should start at 1 and not at 0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyxogen%2Fphilosophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyxogen%2Fphilosophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyxogen%2Fphilosophers/lists"}