{"id":26202451,"url":"https://github.com/f-corvaro/philosophers","last_synced_at":"2025-07-30T15:17:51.706Z","repository":{"id":229053317,"uuid":"775636385","full_name":"f-corvaro/PHILOSOPHERS","owner":"f-corvaro","description":"\"Dive into the world of concurrency with Philosophers, a project that explores the dining philosophers problem.\"","archived":false,"fork":false,"pushed_at":"2025-04-10T08:30:25.000Z","size":4186,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-15T20:44:04.406Z","etag":null,"topics":["42project","c-programming","concurrent-programming","deadlock","dining-philosophers","dining-philosophers-problem","ipc","multiprocessing","multithreading","mutexes","philosophers","race-conditions","semaphores","shared-memory","synchronization","threading","ubuntu"],"latest_commit_sha":null,"homepage":"https://github.com/f-corvaro","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f-corvaro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":"f-corvaro","ko_fi":"fcorvaro"}},"created_at":"2024-03-21T18:55:54.000Z","updated_at":"2025-04-10T08:30:29.000Z","dependencies_parsed_at":"2024-03-21T20:24:22.415Z","dependency_job_id":"2ca0088e-266f-4a74-9445-546a9eabffde","html_url":"https://github.com/f-corvaro/PHILOSOPHERS","commit_stats":null,"previous_names":["f-corvaro/philosophers"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/f-corvaro/PHILOSOPHERS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-corvaro%2FPHILOSOPHERS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-corvaro%2FPHILOSOPHERS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-corvaro%2FPHILOSOPHERS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-corvaro%2FPHILOSOPHERS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f-corvaro","download_url":"https://codeload.github.com/f-corvaro/PHILOSOPHERS/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-corvaro%2FPHILOSOPHERS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267889864,"owners_count":24161295,"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-30T02:00:09.044Z","response_time":70,"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":["42project","c-programming","concurrent-programming","deadlock","dining-philosophers","dining-philosophers-problem","ipc","multiprocessing","multithreading","mutexes","philosophers","race-conditions","semaphores","shared-memory","synchronization","threading","ubuntu"],"created_at":"2025-03-12T03:37:14.295Z","updated_at":"2025-07-30T15:17:51.655Z","avatar_url":"https://github.com/f-corvaro.png","language":"C","funding_links":["https://github.com/sponsors/f-corvaro","https://ko-fi.com/fcorvaro"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\u003ca href=\"https://github.com/f-corvaro/PHILOSOPHERS\"\u003e\n\t\u003cimg src=\"https://github.com/f-corvaro/PHILOSOPHERS/blob/main/.extra/philosophers.png\" alt=\"PHILOSOPHERS\"\u003e\n  \u003c/a\u003e\u003c/h1\u003e\n  \n\u003cp align=\"center\"\u003e\n\t\u003cb\u003e\u003ci\u003e\"Dive into the world of concurrency with Philosophers, a project that explores the dining philosophers problem.\"\u003c/i\u003e\u003c/b\u003e\u003cbr\u003e\n\u003c/p\u003e\n\u003cp align=\"center\" style=\"text-decoration: none;\"\u003e\n    \u003ca href=\"https://github.com/f-corvaro/PHILOSOPHERS\"\u003e\u003cimg alt=\"GitHub code size in bytes\" src=\"https://img.shields.io/github/languages/code-size/f-corvaro/PHILOSOPHERS?color=blueviolet\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/f-corvaro/PHILOSOPHERS\"\u003e\u003cimg alt=\"Code language count\" src=\"https://img.shields.io/github/languages/count/f-corvaro/PHILOSOPHERS?color=yellow\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/f-corvaro/PHILOSOPHERS\"\u003e\u003cimg alt=\"GitHub top language\" src=\"https://img.shields.io/github/languages/top/f-corvaro/PHILOSOPHERS?color=blueviolet\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/f-corvaro/PHILOSOPHERS\"\u003e\u003cimg alt=\"GitHub last commit\" src=\"https://img.shields.io/github/last-commit/f-corvaro/PHILOSOPHERS?color=yellow\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch3 align=\"center\"\u003eIndex\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\n \u003ca href=\"#introduction\"\u003eIntroduction\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#overview\"\u003eOverview\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#folder-structure\"\u003eFolder Structure\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#project-requirements---mandatory-part\"\u003eProject Requirements - Mandatory Part\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#important-guidelines\"\u003eImportant Guidelines\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#specific-rules-for-the-mandatory-part\"\u003eSpecific Rules for the Mandatory Part\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#philosopher-seating-arrangement\"\u003ePhilosopher Seating Arrangement\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#program-name\"\u003eProgram name\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#program-parameters\"\u003eProgram Parameters\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#files-to-submit\"\u003eFiles to Submit\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#allowed-external-functions\"\u003eAllowed External Functions\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#log-format\"\u003eLog Format\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#output-requirements\"\u003eOutput Requirements\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#project-requirements---bonus-part\"\u003eProject Requirements - Bonus Part\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#specific-rules-for-the-bonus-part\"\u003eSpecific Rules for the Bonus Part\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#program-name-1\"\u003eProgram name\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#usage-1\"\u003eUsage\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#program-parameters-1\"\u003eProgram Parameters\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#files-to-submit-1\"\u003eFiles to Submit\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#allowed-external-functions-1\"\u003eAllowed External Functions\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#theoretical-background\"\u003eTheoretical Background\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#threads\"\u003eThreads\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#task-scheduler\"\u003eTask Scheduler\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#process\"\u003eProcess\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#inter-process-communication-ipc\"\u003eInter-Process Communication (IPC)\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#differences-between-process-and-thread\"\u003eDifferences between Process and Thread\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#concurrency-multithreading-vs-multiprocessing\"\u003eConcurrency: Multithreading vs Multiprocessing\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#common-problems-in-concurrent-programming\"\u003eCommon Problems in Concurrent Programming\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#synchronization---mutex-and-semaphore\"\u003eSynchronization - Mutex and Semaphore\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#testing-tools-for-the-philosophers-project\"\u003eTesting Tools for the Philosophers Project\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#developed-skills\"\u003eDeveloped Skills\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#references\"\u003eReferences\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#support-and-contributions\"\u003eSupport and Contributions\u003c/a\u003e\u003cbr\u003e\n \u003ca href=\"#author\"\u003eAuthor\u003c/a\u003e\u003cbr\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\n## Introduction\n\n\u003cp align=\"justify\"\u003e\n\nThe Philosophers project is a classic problem in concurrent programming and synchronization. It aims to explore the dining philosophers problem, which involves simulating the behavior of philosophers sitting at a round table and performing actions such as eating, thinking, and sleeping. The project provides an opportunity to learn about threading, semaphores, mutexes, and shared memory. The challenge lies in ensuring that philosophers never starve and that careful synchronization is implemented to avoid issues like deadlock and race conditions. By working on this project, you can gain hands-on experience in implementing solutions to real-world problems in concurrent computing.\n\n\u003c/p\u003e\n\u003cbr\u003e\n\n### Overview \n\n\u003cp align=\"justify\"\u003e\n\nTo successfully complete the Philosophers project, it is important to have a solid understanding of the following concepts:\n\n- **Multithreading and Multiprocessing:** Familiarity with the distinction between threads and processes, as well as their creation and management, is essential for this project.\n\n- **Concurrency and Synchronization:** Understanding concepts such as race conditions, deadlocks, and starvation is crucial. Additionally, knowing how to utilize synchronization primitives like mutexes and semaphores to prevent these issues is important.\n\n- **Inter-Process Communication (IPC):** In the bonus part, where each philosopher is a separate process, knowledge of inter-process communication techniques is necessary.\n\n\u003c/p\u003e\n\u003cbr\u003e\n\n## Folder Structure\n\n\u003cp align=\"justify\"\u003e\n\n```\n.\n├── philosophers\n│   └── philo\n│       ├── include\n│       │   ├── config.h\n│       │   ├── error_messages.h\n│       │   ├── functions.h\n│       │   ├── macro.h\n│       │   ├── philo.h\n│       │   └── types.h\n│       ├── srcs\n│       │   ├── input\n│       │   │   ├── manipulation.c\n│       │   │   └── validation.c\n│       │   ├── simulation\n│       │   │   ├── cleanup.c\n│       │   │   ├── control.c\n│       │   │   ├── init.c\n│       │   │   ├── philosopher_actions_logger.c\n│       │   │   ├── philosopher_behaviour.c\n│       │   │   └── state.c\n│       │   ├── utils\n│       │   │   ├── error_management.c\n│       │   │   ├── message_handling.c\n│       │   │   └── time_operations.c\n│       │   └── main.c\n│       └── Makefile\n```\n\n\u003cp\u003e\n\n## Project Requirements - Mandatory Part\n\n### Important Guidelines\n\n\u003cp align=\"justify\"\u003e\n\n- The project must be written in C, following the Norm guidelines.\n- Your functions should handle errors gracefully and avoid unexpected crashes or memory leaks.\n- All dynamically allocated memory must be properly freed when no longer needed.\n- Include a Makefile that compiles your source files with the flags -Wall, -Wextra, and -Werror. Use the cc compiler, and ensure that your Makefile does not relink. It should include the rules $(NAME), all, clean, fclean, and re. You can earn bonus points for additional rules.\n- If you have any bonus features, place them in a separate file named _bonus.{c/h}.\n- Do not use global variables.\n\n\u003c/p\u003e\n\n### Specific Rules for the Mandatory Part\n\n - Each philosopher should be represented as a separate thread.\n - There should be one fork between each pair of philosophers. For example, if there are multiple philosophers, each philosopher should have a fork on their left side and a fork on their right side. If there is only one philosopher, there should be only one fork on the table.\n - To ensure that philosophers do not duplicate forks, you should protect the state of each fork using a mutex.\n\n### Philosopher Seating Arrangement\n\n Each philosopher is assigned a number from 1 to `number_of_philosophers`. Philosopher number 1 sits next to philosopher number `number_of_philosophers`. For any other philosopher number N, they sit between philosopher number N - 1 and philosopher number N + 1.\n\n### Program name\n \n `philo`\n\n #### Usage\n\n ```bash\n ./philo 5 800 200 200\n ```\n\n #### Program Parameters\n\n Your program should accept the following arguments:\n\n 1. `number_of_philosophers`: This represents both the number of philosophers and the number of forks.\n 2. `time_to_die` (in milliseconds): This is the maximum time a philosopher can go without eating before they die. It is measured from the start of their last meal or the beginning of the simulation.\n 3. `time_to_eat` (in milliseconds): This is the time it takes for a philosopher to eat. During this time, they must hold two forks.\n 4. `time_to_sleep` (in milliseconds): This is the time a philosopher will spend sleeping.\n 5. `number_of_times_each_philosopher_must_eat` (optional): If all philosophers have eaten at least this many times, the simulation stops. If not specified, the simulation stops when a philosopher dies.\n\n### Files to Submit\n\n To complete the project, you need to submit the following files located in the `philo/` directory:\n\n - `Makefile`: The makefile that compiles the project's source files.\n - `*.h`: Any header files used in the project.\n - `*.c`: All the source code files for the project.\n\n### Allowed External Functions\n\n - Memory management functions: `memset`, `malloc`, `free`\n - Standard I/O functions: `printf`, `write`\n - Time management functions: `usleep`, `gettimeofday`\n - POSIX thread functions: `pthread_create`, `pthread_detach`, `pthread_join`, `pthread_mutex_init`, `pthread_mutex_destroy`, `pthread_mutex_lock`, `pthread_mutex_unlock`\n\n Please note that the use of the `ft_printf` or other functions from the Libft library is not authorized. \n\n### Log Format\n\nThe program should generate logs in the following format:\n\n- `timestamp_in_ms X has taken a fork`\n- `timestamp_in_ms X is eating`\n- `timestamp_in_ms X is sleeping`\n- `timestamp_in_ms X is thinking`\n- `timestamp_in_ms X died`\n\nReplace `timestamp_in_ms` with the current timestamp in milliseconds and `X` with the philosopher number.\n\n### Output Requirements\n\n- Each displayed state message should be distinct and not mixed up with another message.\n- The announcement of a philosopher's death should be displayed within 10 ms after the actual death of the philosopher.\n- Philosophers should strive to avoid dying!\n\n***Your program must ensure there are no data races.***\n\nThis requirement emphasizes the importance of proper synchronization in your implementation. Data races can lead to unpredictable behavior and are a common issue in concurrent programming.\n\n## Project Requirements - Bonus Part\n\n### Specific Rules for the Bonus Part\n\nIn the bonus part of the project, there are specific rules that need to be followed:\n\n- All the forks are placed in the middle of the table.\n- Instead of maintaining states in memory, the number of available forks is represented by a semaphore.\n- Each philosopher should be implemented as a separate process, while the main process should not act as a philosopher.\n\nPlease note that the bonus part will only be evaluated if the mandatory part is completed perfectly. Perfect completion of the mandatory requirements is a prerequisite for the assessment of the bonus part.\n\n### Program name'\n \n `philo_bonus`\n\n  #### Usage\n\n ```bash\n ./philo_bonus 5 800 200 200\n ```\n\n #### Program Parameters\n\n Your program should accept the following arguments:\n\n 1. `number_of_philosophers`: This represents both the number of philosophers and the number of forks.\n 2. `time_to_die` (in milliseconds): This is the maximum time a philosopher can go without eating before they die. It is measured from the start of their last meal or the beginning of the simulation.\n 3. `time_to_eat` (in milliseconds): This is the time it takes for a philosopher to eat. During this time, they must hold two forks.\n 4. `time_to_sleep` (in milliseconds): This is the time a philosopher will spend sleeping.\n 5. `number_of_times_each_philosopher_must_eat` (optional): If all philosophers have eaten at least this many times, the simulation stops. If not specified, the simulation stops when a philosopher dies.\n\n### Files to Submit\n\n To complete the project, you need to submit the following files located in the `philo_bonus/` directory:\n\n - `Makefile`: The makefile that compiles the project's source files.\n - `*.h`: Any header files used in the project.\n - `*.c`: All the source code files for the project.\n\n### Allowed External Functions\n\n - Memory management functions: `memset`, `malloc`, `free`\n - Standard I/O functions: `printf`, `write`\n - Process control functions: `fork`, `kill`, `exit`, `waitpid`\n - POSIX thread functions: `pthread_create`, `pthread_detach`, `pthread_join`\n - Time management functions: `usleep`, `gettimeofday`\n - Semaphore functions: `sem_open`, `sem_close`, `sem_post`, `sem_wait`, `sem_unlink`\n  \n Please note that the use of the `ft_printf` or other functions from the Libft library is not authorized. \n\n## Theoretical Background\n\n\u003cp align=\"justify\"\u003e\n\n### Threads\n\n\u003cp align=\"justify\"\u003e\n\nA thread is the smallest unit of execution within a program, managed independently by a scheduler. It allows a program to perform multiple tasks concurrently. Threads within the same process share the same data space, enabling easier communication and coordination between them.\n\nAn analogy could be drawn to a factory, where each thread represents a worker performing a specific task as part of the production process. Multiple threads can work simultaneously, sharing resources and collaborating to achieve the overall goal of the program.\n\nIn the context of the Philosophers project, each philosopher can be seen as a thread, engaging in actions such as thinking, eating, and sleeping concurrently with other philosophers.\n\n\u003c/p\u003e\n\n### Task Scheduler\n\n\u003cp align=\"justify\"\u003e\n\nA task scheduler, in the context of computer science, is a component of the operating system that manages the execution of processes or threads on the available CPUs.\n\nAn analogy could be drawn to a factory manager who assigns tasks to workers based on various factors such as task priority, resource allocation, and workload balancing. The task scheduler ensures that all running processes or threads receive a fair share of the available CPU time and prevents high-priority tasks from being starved by lower-priority tasks. It is also responsible for efficiently switching the CPU between different tasks, a process known as context switching.\n\nIn a multitasking operating system, the task scheduler plays a crucial role in optimizing resource utilization and maintaining system responsiveness. By efficiently managing the execution of tasks, it helps maximize productivity and ensure smooth operation of the system.\n\n\u003c/p\u003e\n\n### Process\n\n\u003cp align=\"justify\"\u003e\n\nA process is an instance of a computer program that is being executed. It contains the program code and its current activity. Each process has its own separate memory space, ensuring that one process cannot access the variables and data structures of another.\n\nIn the context of computer science, a process can be compared to a project in a factory. Each project (process) has its own set of resources and a dedicated workspace (memory space). Projects (processes) operate independently of each other, with no direct access to each other's resources or workspace. However, they can communicate through specific channels, known as inter-process communication (IPC).\n\nIn the Philosophers project, each philosopher can be seen as a separate process, carrying out their actions (thinking, eating, sleeping) independently of the other philosophers (processes). In the bonus part of the project, each philosopher is implemented as a distinct process.\n\n\u003c/p\u003e\n\n### Inter-Process Communication (IPC)\n\n\u003cp align=\"justify\"\u003e\n\nInter-Process Communication (IPC) is a crucial mechanism that enables processes to communicate and synchronize their actions. It serves as a mail system for processes, allowing them to exchange messages and share data.\n\nIPC mechanisms include pipes, message queues, shared memory, and sockets. These mechanisms facilitate coordination and communication among multiple processes, enabling them to work together effectively.\n\nIn the context of the Philosophers project, IPC plays a vital role in ensuring proper synchronization and data sharing between the philosopher processes. It allows them to coordinate their actions, share information, and avoid conflicts.\n\n\u003c/p\u003e\n\n### Differences between Process and Thread\n\n\u003cp align=\"justify\"\u003e\n\nProcesses and threads are both units of execution within a program, but they have some key differences. \n\nA **process** is an instance of a program that runs independently and has its own memory space. Processes are isolated from each other and communicate through inter-process communication mechanisms. Each process has its own resources and can execute multiple threads. Processes are heavyweight and have higher overhead due to the need for separate memory space.\n\nOn the other hand, a **thread** is a lightweight unit of execution within a process. Threads share the same memory space and resources of the process they belong to. Multiple threads within a process can execute concurrently and communicate through shared memory. Threads are more efficient in terms of memory usage and context switching compared to processes.\n\nIn summary, processes are independent entities with separate memory spaces, while threads are lightweight units within a process that share the same memory space. Processes provide better isolation and stability, while threads offer better performance and resource sharing capabilities.\n\n\u003c/p\u003e\n\n### Concurrency: Multithreading vs Multiprocessing\n\nConcurrency is a fundamental concept in computer science that involves the execution of multiple independent tasks simultaneously. It allows programs to make better use of the CPU and improve overall efficiency. There are two common approaches to achieve concurrency: multithreading and multiprocessing.\n\n**Multithreading** involves dividing a single program into multiple threads that run in parallel. These threads share the same memory space, enabling fast and efficient communication. However, proper synchronization is crucial to prevent conflicts when accessing shared memory.\n\n**Multiprocessing** entails running multiple separate programs (processes) simultaneously. Each process has its own memory space, eliminating the risk of interference. However, inter-process communication (IPC) is required for processes to exchange data and coordinate their actions.\n\nIn the Philosophers project, you have the flexibility to choose between implementing philosophers as threads (mandatory part) or processes (bonus part). Regardless of your choice, careful management of interactions is essential to avoid issues such as race conditions and deadlocks.\n\n\u003c/p\u003e\n\n\n#### Common Problems in Concurrent Programming\n\n\u003cp align=\"justify\"\u003e\n\n1. **Deadlocks**: Deadlocks occur when two or more philosophers are unable to proceed because each is waiting for the other to release a fork. For example, if philosopher A has one fork and needs the other, which is held by philosopher B, who also needs the fork held by philosopher A, neither philosopher can proceed. They are in a deadlock.\n\n2. **Starvation**: Starvation happens when a philosopher is perpetually denied access to the forks and thus cannot eat. This usually occurs in a scheduling system where resources are assigned with priority, and a philosopher keeps getting bumped in favor of others.\n\n3. **Race Conditions**: Race conditions occur when the behavior of the philosophers depends on the relative timing of their actions. For example, if two philosophers try to grab the same fork at the same time, the final state could depend on which philosopher gets to the fork first, leading to unpredictable results.\n\n4. **Livelocks**: Livelocks are similar to deadlocks, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing. Livelocks are a special case of resource starvation.\n\n\u003c/p\u003e\n\n#### Synchronization - Mutex and Semaphore\n\n\u003cp align=\"justify\"\u003e\n\n**Synchronization** is the coordination of simultaneous threads or processes to complete a task, maximizing speed and efficiency while minimizing overlap and conflicts. It ensures that only one thread or process can access a shared resource at a time. This is achieved using synchronization primitives like locks, semaphores, or monitors.\n\nIn the context of the Philosophers project, synchronization is crucial to prevent race conditions when multiple philosophers try to access the same fork simultaneously.\n\nA **mutex** (mutual exclusion) is a synchronization primitive that allows only one thread to access a shared resource at a time. It acts like a key to a bathroom, ensuring exclusive access. When a thread acquires the mutex, no other thread can access the resource until it releases the mutex.\n\nA **semaphore** is a synchronization primitive that controls access to a shared resource using a counter. If the counter is greater than zero, the semaphore allows access. If it's zero, the semaphore blocks until the counter increases. It can be compared to a nightclub bouncer, allowing a certain number of people inside. If the club is full, new people have to wait.\n\nA **monitor** is a synchronization construct that provides mutual exclusion and the ability to wait for a condition to become true. It consists of a mutex and condition variables. Condition variables allow threads to temporarily give up exclusive access and wait for a condition to be met before continuing.\n\n\u003c/p\u003e\n\n## Testing Tools for the Philosophers Project\n\n\u003cp align=\"justify\"\u003e\n\n- [Philosophers Tester by kichkiro](https://github.com/kichkiro/philosophers_tester): A comprehensive tester for the Philosophers project, providing various test cases to ensure the correctness of your implementation.\n- [Philosophers Tester by Aldisti](https://github.com/Aldisti/philosophers-tester): Another useful tester for the Philosophers project, offering a range of scenarios to validate your code.\n- [Philosophers Tester by moulin-louis](https://github.com/moulin-louis/philosophers-tester): A detailed tester designed to help you debug and verify your Philosophers project.\n- [Philosophers Tester by Yoo0lh](https://github.com/Yoo0lh/philosopher_tester): A robust tester for the Philosophers project, featuring multiple test cases to check the reliability of your solution.\n\n## Developed Skills\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://skillicons.dev\"\u003e\n    \u003cimg src=\"https://skillicons.dev/icons?i=git,c,vim,vscode\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\u003cbr\u003e\n\n## References\n\n- [Concurrency in Computer Science](https://en.wikipedia.org/wiki/Concurrency_(computer_science)): An overview of concurrency concepts in computer science.\n- [Dining Philosophers Problem Guide](https://medium.com/@ruinadd/philosophers-42-guide-the-dining-philosophers-problem-893a24bc0fe2): A detailed guide on the Dining Philosophers problem.\n- [Code Vault YouTube Playlist](https://www.youtube.com/playlist?list=PLfqABt5AS4FmuQf70psXrsMLEDQXNkLq2): A playlist of videos covering various concurrency topics.\n- [Threads in Computing](https://en.wikipedia.org/wiki/Thread_(computing)): An introduction to threads and their use in computing.\n- [Understanding Threads](https://philosophers.simple.ink/threads-4cf298dbad9f4c36ba5e01e8a364e102): An in-depth article on threads and their role in concurrent programming.\n- [Semaphore in Operating Systems](https://en.wikipedia.org/wiki/Semaphore_(programming)): Explanation of semaphores and their role in process synchronization.\n- [POSIX Threads Programming](https://computing.llnl.gov/tutorials/pthreads/): A comprehensive tutorial on POSIX threads (pthreads).\n- [Mutexes and Condition Variables](https://www.cs.cmu.edu/afs/cs/academic/class/15492-f07/www/pthreads.html): Detailed information on mutexes and condition variables in pthreads.\n- [Dining Philosophers Problem on GeeksforGeeks](https://www.geeksforgeeks.org/dining-philosopher-problem-using-semaphores/): An article explaining the Dining Philosophers problem using semaphores.\n\u003cbr\u003e\n\n## Support and Contributions\n\n\u003cp align=\"center\"\u003e\nIf you find this repository helpful, please consider starring it to show your support. Your support is greatly appreciated!\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://ko-fi.com/fcorvaro\"\u003e\u003cimg width=\"180\" img align=\"center\" src=\"https://github.com/f-corvaro/42.common_core/blob/main/.extra/support-me-ko-fi.svg\"\u003e\u003calt=\"\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/sponsors/f-corvaro\"\u003e\u003cimg width=\"180\" img align=\"center\" src=\"https://github.com/f-corvaro/42.common_core/blob/main/.extra/support-me-github.svg\"\u003e\u003calt=\"\"\u003e\u003c/a\u003e\n\n\u003cbr\u003e\n\n## Author\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://profile.intra.42.fr/users/fcorvaro\"\u003e\u003cimg style=\"height:auto;\" src=\"https://avatars.githubusercontent.com/u/102758065?v=4\" width=\"100\" height=\"100\"alt=\"\"\u003e\u003c/a\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"mailto:fcorvaro@student.42roma.it\"\u003e\u003ckbd\u003eEmail\u003c/kbd\u003e\u003calt=\"\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/f-corvaro\"\u003e\u003ckbd\u003eGithub\u003c/kbd\u003e\u003calt=\"\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.linkedin.com/in/f-corvaro/\"\u003e\u003ckbd\u003eLinkedin\u003c/kbd\u003e\u003calt=\"\"\u003e\u003c/a\u003e\n\u003ca href=\"https://42born2code.slack.com/team/U050L8XAFLK\"\u003e\u003ckbd\u003eSlack\u003c/kbd\u003e\u003calt=\"\"\u003e\u003c/a\u003e\n\n\u003chr/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-corvaro%2Fphilosophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff-corvaro%2Fphilosophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-corvaro%2Fphilosophers/lists"}