If you're looking for the meaning of life, the answer you need is in a book called "Running on Empty" by Jonice Webb.
I spent sixteen years investigating physics and philosophy and all kinds of bullshit but it's all laid out in there.
Good luck!
Sunday, March 31, 2019
Monday, March 25, 2019
keeping a mental model of threading when writing low-level multithreaded code
You have a tree of objects in your program, e.g.
But there is also a tree of threads!
It is important to always keep BOTH mental models in your head when writing C++ code. Just like you need to track which object owns which other object (for freeing memory and avoiding memory leaks), you ened to track which thread is executing each line of code (for avoiding race conditions). This is a very common error in c++ programming, and several patterns have sprung up to avoid having to think about it. Debugging race conditions is very difficult because they are non-deterministic (they may not occur on every execution of the program, making them hard to test repeatably).
Patterns for avoiding thinking about threading in c++ include
But there is also a tree of threads!
It is important to always keep BOTH mental models in your head when writing C++ code. Just like you need to track which object owns which other object (for freeing memory and avoiding memory leaks), you ened to track which thread is executing each line of code (for avoiding race conditions). This is a very common error in c++ programming, and several patterns have sprung up to avoid having to think about it. Debugging race conditions is very difficult because they are non-deterministic (they may not occur on every execution of the program, making them hard to test repeatably).
Patterns for avoiding thinking about threading in c++ include
- a god object with locks (the worst option, not really multi-threaded)
- message passing (erlang, golang channels, "event-driven" frameworks)
- immutable objects (functional languages)