How mcombeau/philosophers works
Main components
• Input/Configuration: Represents the command-line argument parsing that sets up simulation variables such as the number of philosophers, time constraints, and optionally, how many times each philosopher must eat.
• Simulator/Initializer Module: The initialization routines (e.g., init.c) are responsible for setting up the simulation, creating philosopher entities, and initializing forks (mutexes for the thread version; semaphores for the processes version).
• Philosopher Entity: Each philosopher is represented by a thread (in "philo") or a process (in "philo_bonus"). These components are responsible for executing the philosopher routines (eat, sleep, think) and handling shared resources.
• Forks/Resources Manager: In the mandatory part, each fork is modeled as a mutex residing between philosophers. In the bonus part, a counting semaphore represents the pool of available forks.
• Monitor: The "grim_reaper.c" file indicates a monitoring module that checks whether a philosopher has exceeded his time limit and has died.
• Output Module: The output routines (such as output.c) are used to print timestamped actions of each philosopher including taking a fork, eating, sleeping, thinking, and dying.
Relationships and interactions
• The Input/Configuration component feeds parameters into the Initializer.
• The Initializer creates and spawns multiple Philosopher Entities, each operating concurrently using either threads or separate processes.
• Each Philosopher Entity interacts with the Forks/Resources Manager to acquire or release forks when eating.
• The Monitor component continuously observes the state of each philosopher, signaling if a philosopher dies (triggering the corresponding exit routines).
• The Output Module logs various state changes across the system, showing real-time activity based on scheduled operations.
Architectural patterns and design principles
• Concurrency Management – Use of threads and mutexes in one implementation versus processes and semaphores in the other.
• Modularity – Separation of concerns is clear in the source files. Each file (init.c, philosopher.c, managing time, cleanup, etc.) corresponds to a specific role in the simulation.
• Resource Synchronization – The system employs different synchronization primitives depending on the implementation. (A clear depiction of mutex-protected forks versus semaphore-protected fork pools will be important.)