Skip to content
Lunna Boo edited this page Aug 8, 2026 · 8 revisions

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

Disclaimer

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.


Backlog

Parser

  1. Make it accept only 8 arguments, no more no less.
  2. Check all their types and return errors

Structs

Coder

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

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

Main Thread

  • 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

Coder Routine

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)

Monitor Thread

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

Communication between Threads

  1. Routine Thread locks mutex, updates last_compile = get_time(), unlocks mutex.
  2. Monitor Thread locks same mutex, reads last_compile, calculates elapsed time.
  3. Monitor Thread detects death, locks mutex, prints log, sets dead_flag = 1, unlocks mutex.
  4. 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.

Rules

  • Always pass everything by reference. Most importantly structs.
  • When accessing arguments inside routines always cast the argument from void * back to the desired type.

Clone this wiki locally