-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to my Codexion's wiki! Take a look at the [GUIDE] pages in case you're developing your own Codexion or if curious about my development process and decisions. o7
Everything below this point is outdated and was written by me in the first day of development mostly using this guide https://medium.com/@ruinadd/philosophers-42-guide-the-dining-philosophers-problem-893a24bc0fe2 to sketch the project's core. Writing down a plan like this one may seem like a waste of time, but having a basic plan of what your project will look right from the beginning actually saves time in comparison to coding blindly.
When doing this avoid over-using AI, do not hand architecture decisions to a machine or IT WILL backfire. You've been warned.
- 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 = long
- 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.
- Always pass everything by reference. Most importantly structs.
- When accessing arguments inside routines always cast the argument from void * back to the desired type.