By: EduardoS (no.delete@this.spam.com), July 13, 2015 4:56 pm
Room: Moderated Discussions
Wilco (Wilco.Dijkstra.delete@this.ntlworld.com) on July 13, 2015 4:36 pm wrote:
> The point is, you can't. Ignoring the fact most people wouldn't understand the intricate details of
> say the x86 memory model and its various gotcha's, there is something called a "compiler". And a compiler
> will reorder loads and stores according to the language rules, typically assuming no multithreading
> unless special annotations are added (eg. volatile, intrinsics or the C++11 atomics).
>
> Whatever memory model you're targeting, you always need those annotations. When annotated correctly there is
> actually little difference between the different memory models - some annotations cause special loads/stores
> to be emitted, some become barriers, some are just nops and only compiler optimization barriers. So it is more
> correct to say that compilers will automatically take advantage of the memory model when supplied with correct
> annotations. They can even optimize away redundant barriers when they can prove they aren't required.
That's true, but writing those annotations are f***ing hard, so, as I understand Linus is asking for a clear behavior for variable load.
But actually those annotations are required even on x86 with the most conservative compiler, on more aggressive compilers many of those annotations become just useless because the C standard is so stupid in requiring so few guarantees for them.
> The point is, you can't. Ignoring the fact most people wouldn't understand the intricate details of
> say the x86 memory model and its various gotcha's, there is something called a "compiler". And a compiler
> will reorder loads and stores according to the language rules, typically assuming no multithreading
> unless special annotations are added (eg. volatile, intrinsics or the C++11 atomics).
>
> Whatever memory model you're targeting, you always need those annotations. When annotated correctly there is
> actually little difference between the different memory models - some annotations cause special loads/stores
> to be emitted, some become barriers, some are just nops and only compiler optimization barriers. So it is more
> correct to say that compilers will automatically take advantage of the memory model when supplied with correct
> annotations. They can even optimize away redundant barriers when they can prove they aren't required.
That's true, but writing those annotations are f***ing hard, so, as I understand Linus is asking for a clear behavior for variable load.
But actually those annotations are required even on x86 with the most conservative compiler, on more aggressive compilers many of those annotations become just useless because the C standard is so stupid in requiring so few guarantees for them.