-
Notifications
You must be signed in to change notification settings - Fork 0
Home
- Make it accept only 8 arguments, no more no less.
- Check all their types and return errors
It needs to have:
- thread = pthread_t
- id = int
- is_compiling = int
- compiling_score = int | NEEDS LOCK TO READ/WRITE
- last_compile = long | NEEDS LOCK TO READ/WRITE
- r_dongle = *pthread_mutex_t
- l_dongle = *pthread_mutex_t
- dead_lock = *pthread_mutex_t
- compile_lock = *pthread_mutex_t
- print_lock = *pthread_mutex_t
- sim = *t_simulation
- thread = pthread_t
- nb_of_coders = int
- start_time = long
- dead_flag = int
- dead_lock = pthread_mutex_t
- compile_lock = pthread_mutex_t
- print_lock = pthread_mutex_t
- time_to_burn = long
- time_to_compile = long
- time_to_debug = long
- time_to_refac = long
- compiling_quota = int
- dongle_cooldown = float
- scheduler = char *
- *coders = t_coders
-
Create Coder and Simulation Structs
-
Initialize both of them
-
Create both coder_routine thread and monitor thread (passing the structs as arguments)
-
coder_routine argument will be simulation.coders[i] (gotta get the right coder struct to it)
-
monitor argument will be the simulation struct itself
-
pthread_join both threads.
-
destroy all mutexex.
-
free all allocated data
Must:
-
Cast arg to t_coder * / t_coder *coder = (t_coder *)arg;
-
Check if simulation dead-flag is 1 / if it is, exit
-
Print each time a coder takes a dongle (timestamp id has taken a dongle!)
-
Compile and print / Lock dongles, update last_compile, lock print mutex, print, unlock print, and unlock dongles
-
Debug, lock print mutex, print and unlock
-
Refactor, lock print mutex, print and unlock
-
Serialize logging (never have 2 outputs on a single line)
Must:
- Cast arg to t_simulation * / t_simulation *simulation = (t_simulation *)arg;
- Loop every 1ms
- Detect burnout and stop the simulation. (read last_compile, using mutex)
- If burnout detected, lock print mutex, print death log, set dead_flag = 1 and unlock
It will detect burnout by checking
- Routine Thread locks mutex, updates last_compile = get_time(), unlocks mutex.
- Monitor Thread locks same mutex, reads last_compile, calculates elapsed time.
- Monitor Thread detects death, locks mutex, prints log, sets dead_flag = 1, unlocks mutex.
- Routine Thread (at the top of its loop, or after waking from sleep) checks: if (dead_flag == 1) return (NULL); and exits without printing anything.