How oait-h-m/philosophers works
Project Type and Purpose
• This is a single‐process, multi‐threaded C application that simulates the Dining Philosophers synchronization problem.
• It reads command‐line arguments, initializes shared resources (forks as mutexes), spawns philosopher threads, and runs a monitor thread to detect termination conditions.
File Structure
• Top‐level sources:
– main.c: entry point, high‐level orchestration
– init.c: resource/module initialization (parsing args, allocating forks)
– simulation.c: philosopher thread logic (eat/think cycles)
– monitor.c: “observer” thread logic (checks for death or completion)
– pars_arguments.c: CLI parsing
– utils.c: logging, time utilities
– philo.h: shared data structures, type definitions
• Build artifact: Makefile
README for Insights
• Describes goal: manage N philosopher threads competing for N forks (mutexes) without deadlock/starvation.
• No external services—purely an in‐memory concurrency simulation.
Main Components & Their Relationships
a. Components
1) CLI / Argument Parser
2) Simulation Controller (Initialization + Resource Manager)
3) Philosopher Threads (N workers)
4) Fork Resources (array of N mutexes)
5) Monitor Thread (observer)
6) Utility Module (timing/logging)
b. Interactions
– CLI → Argument Parser: User inputs → parsed config (N, times)
– Parser → Controller: feeds configuration data
– Controller → Fork Resources: allocates & initializes mutexes
– Controller → Spawns Philosopher Threads & Monitor Thread
– Philosopher Threads ↔ Fork Resources: lock/unlock ordering
– Monitor Thread → Philosopher Threads & Controller: reads shared state to detect death/completion
– Any Thread → Utility Module: timestamped logging
c. Architectural Patterns
– Concurrency via pthreads
– “Resource Allocation” pattern: forks as shared mutexes
– Observer pattern: monitor thread watches thread states
d. Key Technologies
– C standard library
– POSIX threads (pthread_mutex_t, pthread_create, pthread_join)
– Makefile build system