philosophers_prep/subjects/8_simple_philosophers.txt

19 lines
949 B
Plaintext

Assignment name: simple_philosophers
Expected files: simple_philosophers.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 a simplified version of the dining philosophers problem:
- 3 philosophers seated at a circular table
- 3 forks (one between each pair of philosophers)
- Each philosopher alternates between: thinking (1s) → grabbing forks → eating (1s) → dropping forks → repeat
- Program runs for 10 seconds and then stops
Each action should be printed: `[timestamp] Philosopher X is thinking/eating`
Usage: `./simple_philosophers`
Hint: This is the core of the Philosophers project. Each fork is protected by a mutex.
To avoid deadlock, implement a consistent order for grabbing forks (fork with lower ID first).
Use a monitor thread to stop after 10s.