← cd ~ ~/42-firenze/codexion
42 firenze · milestone 3 · c

Codexion

A concurrency problem in the spirit of the dining philosophers. N coders sit around a table with one USB dongle between each pair. A coder needs both neighbouring dongles to compile, and burns out if too much time passes since their last compile. Every coder is a POSIX thread. Every dongle is a mutex with a condition variable, and a hand-written priority queue decides who gets a released dongle first.

cpthreadsmutex / condvarmin-heapfifo / edfthreadsanitizer
replay
log
dongle free
coder holds it, waiting for the second one
coder holds both: compiling
just released, cooling down
coder ring = time since last compile
timeline · click or drag to scrub
waitingholding one donglecompilingdebuggingrefactoringburnout

Two real runs with identical parameters, replayed: . With EDF every coder finishes; with FIFO one burns out. Thread timing varies, so every run is different. The log only says "has taken a dongle": the dongle ids come from the code, where coder i owns dongles i and i+1 and always locks the lower one first.

how it works

view source on github ↗teemoteeo/quarantadue/milestone_3/codexion