philosophers_prep/subjects/9_death_monitor.txt

21 lines
1006 B
Plaintext

Assignment name: death_monitor
Expected files: death_monitor.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
---------------------------------------------------------------------------------------
Create a system with:
- 4 "worker" threads that do work for varied periods (1-4 seconds)
- 1 monitor thread that checks if any worker hasn't given a "sign of life" for more than 3 seconds
- Workers must update `last_activity_time` at each iteration
- Monitor checks every 100ms and prints warning if it detects a "dead" worker
Simulate "death" by making a worker stop randomly.
Usage: `./death_monitor`
Hint: This exercise simulates death detection in Philosophers.
The monitor thread must check continuously without blocking the workers.
Use mutex to protect `last_activity_time`.
Detection must be fast (within 10ms in the real project).