philosophers_prep/subjects/10_philosophers_args.txt

22 lines
1.2 KiB
Plaintext

Assignment name: philosophers_args
Expected files: philosophers_args.c
Allowed functions: memset, printf, malloc, free, write, pthread_create,
pthread_detach, pthread_join, pthread_mutex_init, pthread_mutex_destroy,
pthread_mutex_lock, pthread_mutex_unlock, usleep, gettimeofday
------------------------------------------------------------------------
Implement the complete philosophers problem with argument parsing:
Arguments: `number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_must_eat]`
Behavior:
- Each philosopher alternates: thinking → trying to grab forks → eating → dropping forks → sleeping
- If a philosopher doesn't eat within `time_to_die`, they die and the program terminates
- If `number_of_times_must_eat` is specified, the program terminates when all have eaten that many times
- Monitor thread checks for deaths every 1ms
Usage: `./philosophers_args 5 800 200 200` or `./philosophers_args 5 800 200 200 7`
Hint: This is practically the complete Philosophers project.
Implement robust argument parsing, input validation, and proper resource cleanup.
The monitor thread is critical - it must detect death quickly without affecting performance.