{"id":19675463,"url":"https://github.com/kuninoto/42_philosophers","last_synced_at":"2025-09-13T05:48:34.303Z","repository":{"id":157766205,"uuid":"583320505","full_name":"Kuninoto/42_Philosophers","owner":"Kuninoto","description":"Philosophers dinner problem in C. Introduction to parallel programming.","archived":false,"fork":false,"pushed_at":"2025-03-28T21:33:07.000Z","size":354,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T12:42:03.001Z","etag":null,"topics":["42","42-cursus","42-philosophers","42-school","42born2code","42cursus","42ecole","42porto","42portugal","42projects","42school","ecole42","philosophers-42","philosophers-dinner-problem","philosophers42","school42"],"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/Kuninoto.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-12-29T12:30:15.000Z","updated_at":"2025-03-28T21:33:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"220b1ead-6aa2-4d48-b128-36b919beb608","html_url":"https://github.com/Kuninoto/42_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/Kuninoto%2F42_Philosophers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuninoto%2F42_Philosophers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuninoto%2F42_Philosophers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuninoto%2F42_Philosophers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kuninoto","download_url":"https://codeload.github.com/Kuninoto/42_Philosophers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251420884,"owners_count":21586697,"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","42-cursus","42-philosophers","42-school","42born2code","42cursus","42ecole","42porto","42portugal","42projects","42school","ecole42","philosophers-42","philosophers-dinner-problem","philosophers42","school42"],"created_at":"2024-11-11T17:24:14.364Z","updated_at":"2025-04-29T02:30:37.450Z","avatar_url":"https://github.com/Kuninoto.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Philosophers (42Porto - 42Cursus)  \n\n![](./extras/showcase.gif)\n\n## Description  \n\n[Dining philosophers problem](https://en.wikipedia.org/wiki/Dining_philosophers_problem) in C; A version with threads (/philo) and another with processes (/philo_bonus). Introduction to parallel programming.\n\n## Grade: 100/100  \n\n### Installing and running the project  \n\n1- Clone this repository\n\t\n\tgit clone https://github.com/Kuninoto/42_Philosophers philosophers\n2- Navigate to the version of the project you wish to run\n\n\tcd philosophers/\u003cphilo|philo_bonus\u003e\n3- Compile and clean the object files that you won't need anymore\n\n\tmake \u0026\u0026 make clean\n3- Run your new dining philosopher simulation program!\n\n\t./philo \u003cnbr_of_philos\u003e \u003ctime_to_die\u003e \u003ctime_to_eat\u003e \u003ctime_to_sleep\u003e [nbr_of_times_each_philo_must_eat]\n\n#### Side note/warning for 42 students  \nI did the bonus part but I did not deliver it, it isn't in its final form and neither I tested it\nsufficiently to guarantee that it's fully working.  \n\n#### Makefile available targets  \n`make` or `make all` - compiles `philo` or `philo_bonus` (depending on the version of the project you're running)   \n`make clean` - wipes all object files   \n`make fclean` - deletes executable and all object files   \n`make re` - `fclean` + `all`  \n\n### Useful links  \nGeneral thread understanding:  \n[Introduction to threads (pthreads) | C programming](https://www.youtube.com/watch?v=ldJ8WGZVXZk)  \n[How to create and join threads in C (pthreads)](https://www.youtube.com/watch?v=uA8X5zNOGw8\u0026list=PL9IEJIKnBJjFZxuqyJ9JqVYmuFZHr7CFM)  \n[Short introduction to threads (pthreads)](https://www.youtube.com/watch?v=d9s_d28yJq0\u0026list=PLfqABt5AS4FmuQf70psXrsMLEDQXNkLq2)  \n[Multithreading in C](https://www.geeksforgeeks.org/multithreading-c-2/)  \n[What are race conditions](https://www.youtube.com/watch?v=FY9livorrJI)  \n[How to create threads in a loop (pthread_create)](https://www.youtube.com/watch?v=xoXzp4B8aQk)  \n\nThreads vs. Processes:  \n[Difference between process and thread](https://www.geeksforgeeks.org/difference-between-process-and-thread/)  \n[Difference between processes and threads](https://www.youtube.com/watch?v=IKG1P4rgm54)  \n\nMutex:  \n[What is a mutex in C? (pthread_mutex)](https://www.youtube.com/watch?v=oq29KUy29iQ)  \n[Mutex lock for Linux Thread Synchronization](https://www.geeksforgeeks.org/mutex-lock-for-linux-thread-synchronization/)  \n\nGeneral semaphore understanding:  \n[Semaphores in Process Synchronization](https://www.geeksforgeeks.org/semaphores-in-process-synchronization/)  \n[How to use POSIX semaphores in C language](https://www.geeksforgeeks.org/use-posix-semaphores-c/)  \n[Introduction to semaphores in C](https://www.youtube.com/watch?v=YSn8_XdGH7c)  \n[Semaphores](https://www.youtube.com/watch?v=XDIOC2EY5JE)  \n[What is a semaphore? How do they work? (Example in C)](https://www.youtube.com/watch?v=ukM_zzrIeXs)  \n[Inter Process Communication - Semaphores](https://www.tutorialspoint.com/inter_process_communication/inter_process_communication_semaphores.htm)  \n[Can Semaphore Be Initialized To Negative?](https://www.timesmojo.com/can-semaphore-be-initialized-to-negative/)  \n[When to call sem_unlink()?](https://stackoverflow.com/questions/15164484/when-to-call-sem-unlink)  \n\nMutex vs. Semaphore:  \n[Mutex vs Semaphore](https://www.geeksforgeeks.org/mutex-vs-semaphore/)  \n[Semaphore Vs. Mutex - A Clear Understanding](https://www.youtube.com/watch?v=8wcuLCvMmF8)  \n\nMutex vs. Semaphore Cheatsheet:  \n\u003ctable\u003e\n \u003ctr\u003e\n   \u003cth\u003eMutex\u003c/th\u003e\n   \u003cth\u003eSemaphore\u003c/th\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n   \u003ctd\u003eBehaves like a lock\u003c/td\u003e\n   \u003ctd\u003eBehaves like a limited inventory\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n   \u003ctd\u003e\u003ccode\u003epthread_mutex_lock()\u003c/code\u003e\u003c/td\u003e\n   \u003ctd\u003e\u003ccode\u003esem_wait()\u003c/code\u003e, decrements the counter, when the counter reaches 0, calling it again makes the process wait.\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\u003ccode\u003epthread_mutex_unlock()\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003ccode\u003esem_post()\u003c/code\u003e, increments the counter\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/table\u003e\n\n[fork() IBM documentation](https://www.ibm.com/docs/en/zos/2.1.0?topic=functions-fork-create-new-process#rtfor)  \n[waitpid() IBM documentation](https://www.ibm.com/docs/en/zos/2.1.0?topic=functions-waitpid-wait-specific-child-process-end)  \n[sem_open() IBM documentation](https://www.ibm.com/docs/en/i/7.1?topic=ssw_ibm_i_71/apis/ipcsemo.html)  \n\nInter Process Communication  \n[Shared memory](https://www.tutorialspoint.com/inter_process_communication/inter_process_communication_shared_memory.htm)  \n\n## Disclaimer  \n\u003e At [42School](https://en.wikipedia.org/wiki/42_(school)), almost every project must be written in accordance to the \"Norm\", the schools' coding standard. As a result, the implementation of certain parts may appear strange and for sure had room for improvement.\n\n---\nMade by Nuno Carvalho (Kuninoto) | nnuno-ca@student.42porto.com  \n\u003cdiv id=\"badge\"\u003e \u003ca href=\"https://www.linkedin.com/in/nuno-carvalho-218822247\"/\u003e \u003cimg src=\"https://img.shields.io/badge/LinkedIn-blue?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\" alt=\"LinkedIn Badge\"/\u003e\u0026nbsp;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuninoto%2F42_philosophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuninoto%2F42_philosophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuninoto%2F42_philosophers/lists"}