Also, longer term, would you be willing to add code that makes a
simple but dangerous change in order to better illustrate the problem?
I sent a patch, but I'm actually not too thrilled with it.
The original code was using nd->children[i], which I believe forces a
compliant compiler to re-read nd->children, avoiding the problem. I was
unable to get GCC 8.3 to cache nd->children, even when making the
iterator and the callback take a pointer to a const node. With the new
version, which uses an explicit iterator, the compiler does store
nd->children in a register that is not reloaded across the loop.
The example I propose can thus fall under the category of "don't do
that". On the other hand, this is just supposed to be a small,
self-contained illustration of the danger.
What do you think?
--Elad