Caching globals in registers
Florian Weimer
fw@deneb.enyo.de
Sun Nov 5 19:36:00 GMT 2017
* jacob navia:
>
> One of the reasons (besides the nullity of my code generator of course)
> was that gcc cached the values of the global "table" in registers,
> reading it just once. Since there are many accesses in the most busy
> function in the program, gcc speeds up considerably.
>
> Clever, but there is a problem with that: the generated program becomes
> completely thread unfriendly. It will read the value once, and then,
> even if another thread modifies the value, it will use the old value.
Have you tried using relaxed atomics?
More information about the Gcc
mailing list