lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Fri, Apr 28, 2023 at 5:01 PM Hive Heap <hive.heap@gmail.com> wrote:
That's interesting, could you send me the link where it states that? I Want to read more about it. Regardless, I still think this is a bit illogical behavior, considering how it's written, but good to know.

There's some discussion here:
https://en.m.wikipedia.org/wiki/Memory_ordering#Compile-time_memory_ordering#Compile-time_memory_ordering

There's lots more when you google "compiler memory reordering".

Another issue is that the processor does not execute instructions in order either, at least high performance processors don't. Memory is slow relative to the processor so the CPU would be waiting for memory most of the time if it was not clever about it.
That is typically hidden from the programmer until you start using multi-core processors and multithreading, or you are writing device drivers. Here's Herb Sutter's 2012 talk about it, in two parts:

https://youtu.be/A8eCGOqgvH4
https://youtu.be/KeLBd2EJLOU

Warning: this gets really hairy really fast, and is an endless source of entertaining bugs. When you port software from Intel/AMD to ARM the difference in memory models can expose all kinds of fun problems.


--