{"id":28482508,"url":"https://github.com/abdocooder/philo","last_synced_at":"2025-07-05T05:03:29.795Z","repository":{"id":297640377,"uuid":"970763636","full_name":"AbdoCooder/philo","owner":"AbdoCooder","description":"Summary: In this project, you will learn the basics of threading a process. You will learn how to create threads and explore the use of mutexes. (Version: 11.2)","archived":false,"fork":false,"pushed_at":"2025-06-06T14:42:13.000Z","size":1565,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-06T15:36:16.102Z","etag":null,"topics":["c","mutexes","philosophers","philosophers-dinner-problem","synchronization","thread"],"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/AbdoCooder.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,"zenodo":null}},"created_at":"2025-04-22T13:56:15.000Z","updated_at":"2025-06-06T14:44:08.000Z","dependencies_parsed_at":"2025-06-06T15:47:48.091Z","dependency_job_id":null,"html_url":"https://github.com/AbdoCooder/philo","commit_stats":null,"previous_names":["abdocooder/philo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AbdoCooder/philo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbdoCooder%2Fphilo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbdoCooder%2Fphilo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbdoCooder%2Fphilo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbdoCooder%2Fphilo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AbdoCooder","download_url":"https://codeload.github.com/AbdoCooder/philo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbdoCooder%2Fphilo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262343630,"owners_count":23296366,"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":["c","mutexes","philosophers","philosophers-dinner-problem","synchronization","thread"],"created_at":"2025-06-07T20:37:48.910Z","updated_at":"2025-07-05T05:03:29.790Z","avatar_url":"https://github.com/AbdoCooder.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🍝 Philosophers\n\nWelcome to `philo`, a concurrency-focused simulation of the classic Dining Philosophers Problem. This project dives deep into process synchronization, thread management, and mutexes using only low-level tools available in C. Built under strict 42 coding standards and without external libraries, this is a true test of threading discipline.\n\n## 🚀 Features\n\n* 🤴 Philosophers eat, sleep, and think in proper cycles\n* ⚖️ Precise timing control for life and death simulation\n* 🛏️ Mutex-based fork handling to prevent race conditions\n* ⏱ Accurate timestamped state logging\n* 🚫 No global variables allowed\n* 🧪 Death detection within 10ms margin\n* ⚠️ Manual memory management (no leaks allowed)\n\n## 🎖️ Bonus Features (if unlocked)\n\n\u003e Bonuses are only considered if the mandatory part is flawless.\n\n* ⚔️ Philosopher processes instead of threads\n* ⚖️ Semaphores instead of mutexes\n* 🚪 Forks placed centrally with access managed via semaphores\n* 🌁 Multiple process management using `fork()` and `waitpid()`\n\n## 🔢 Program Arguments\n\n```bash\n./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]\n```\n\n* `number_of_philosophers`: Number of philosophers and forks\n* `time_to_die`: Time (ms) before a starving philosopher dies\n* `time_to_eat`: Time (ms) taken to eat (holding both forks)\n* `time_to_sleep`: Time (ms) spent sleeping after eating\n* `number_of_times_each_philosopher_must_eat`: *(optional)* Simulation ends if all have eaten this many times\n\n## 📊 Example Output\n\n```text\n0 1 is thinking\n5 1 has taken a fork\n6 1 has taken a fork\n7 1 is eating\n17 1 is sleeping\n27 1 is thinking\n...\n105 2 died\n```\n\n## 💪 Compilation\n\n```bash\nmake          # Build mandatory (threads + mutexes)\nmake bonus    # Build bonus (processes + semaphores)\nmake clean    # Remove object files\nmake fclean   # Remove object files and executables\nmake re       # Full rebuild\n```\n\n## 🧐 Concepts Practiced\n\n* Thread creation and management (`pthread_create`, `pthread_join`)\n* Mutex usage for resource protection (`pthread_mutex_lock`, `unlock`)\n* Race condition prevention\n* Accurate logging and printing without overlapping outputs\n* Timestamp handling with `gettimeofday`\n* Process forking and semaphore control (bonus)\n\n## ⚙️ Dependencies\n\n* POSIX threads (`pthread`)\n* Time functions (`usleep`, `gettimeofday`)\n* For bonus:\n\n  * Process control (`fork`, `kill`, `waitpid`)\n  * Semaphores (`sem_open`, `sem_post`, `sem_wait`, ...)\n\n## 📂 Directory Structure\n\n```\nphilo/\n|-- Makefile\n|-- *.c\n|-- *.h\n\nphilo_bonus/\n|-- Makefile\n|-- *_bonus.c\n|-- *_bonus.h\n```\n\n## 🔗 External Functions Allowed\n\n```c\nmemset, printf, malloc, free, write,\nusleep, gettimeofday, pthread_create,\npthread_detach, pthread_join,\npthread_mutex_init, pthread_mutex_destroy,\npthread_mutex_lock, pthread_mutex_unlock\n\n// Bonus Only:\nfork, kill, exit, waitpid,\nsem_open, sem_close, sem_post, sem_wait, sem_unlink\n```\n\n## 📃 Reference Reading\n\n* [Dining Philosophers Problem](https://en.wikipedia.org/wiki/Dining_philosophers_problem)\n* [POSIX Threads Programming](https://man7.org/linux/man-pages/man7/pthreads.7.html)\n* [Semaphore Tutorial](https://man7.org/linux/man-pages/man7/sem_overview.7.html)\n\n---\n\n\u003e ⛨️ Built for 42cursus — Norminette approved. May the philosophers live long and prosper.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdocooder%2Fphilo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabdocooder%2Fphilo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdocooder%2Fphilo/lists"}