I've worked in Erlang/Elixir for the past few years and I haven't had the opportunity to work "in anger"[0] with languages with traditional threads/mutexes/sempahores. This game was a blast and made me appreciate the Erlang's approach to concurrency. The best beginner resouce I've read on Erlang's concurrency model is here https://learnyousomeerlang.com/the-hitchhikers-guide-to-conc...
You made an awesome game that really hits home the concept that arbitrary execution interleavings throws a wrench in poorly designed concurrent algorithms.
Really like the gamification, reverse presentation/adversarial mode of thinking.
I now generally avoid concurrency mechanisms that don't compose but this could have been useful for learning and communicating issues that aren't otherwise easy to illustrate to someone who doesn't already 'get it'.
I wish this had at least one more problem that it could highlight: synchronization using sleep() without atomics. A call to sleep() isn't guaranteed to flush cache and so the classic problem is that you could have two threads waiting on a bool and neither of them seeing updates from the other thread.
Cache coherency is almost never the right thing to think about with shared memory concurrency. It's all about interleaving of instruction execution and possible reordering of memory reads or writes.
If by sleep(), you mean a spin loop, its possible that the compiler has reordered a write past an empty loop that appears to have no side effects. If you're talking about an OS API to delay execution, then sleep should allow other threads to see the writes done before the sleep. It's just not a great way to synchronize compared to a condition variable since sleep waits for some arbitrary amount of time rather than exactly as much as is needed to observe a change.
I loved these puzzles. I was reminded of the famous book by Tony Hoare "Communicating Sequential Processes". In that book, he describes the trace of a parallel program as all possible interleaving of the traces of the individual programs
It looks like this game uses a very strong memory model. Loads and stores cannot be re-ordered and are immediately visible to all threads. Many languages and architectures have weaker memory models than that.
I don't doubt someone has built something like that for testing, though perhaps not as a library. I'm reminded of a networking service that does the same at a higher level, given its easy to remember name : https://github.com/tylertreat/comcast
[0] https://erlang-in-anger.com/