I am working on an equivalent to the Dining Philosopher problem in C.
Our subject has a few new rules, adding a Resting state and the following rule:
"The states 'think' and 'eat' have a maximum duration that you'll have to determine."
The following structure has a state
variable:
typedef struct philo_s
{
pthread_t handler; // The thread of the philosopher
char state; // Either 'E' for eat, 'T' for think or 'R' for rest
int dur_think; // Defines the maximum duration of the think state
int dur_eat; // Defines the maximum furation of the eat state
int max_eat;
int num;
} philo_t;
What I have understood from the rule stated above, is that a given thread can't have the same state for a given amount of time.
So how may I monitor a structure to see if it has had the same value for a defined amount of seconds?
If philosopher 1 can't be in an Eat state for more then one second and he reaches that limit, I will perhaps force him into another state.
Code does not seem relevant since the functions are simply conditions to change the philosophers states.