Thanks for the correction. But the compiler is still correct here. Volatile doesn't say anything about restricting _when_ it is read or written, only that it will get the "latest" value in a single-thread context.
It's perfectly fine for I/O as long as you can guarantee alignment such that there is no "false sharing."
Posted Feb 7, 2012 19:07 UTC (Tue) by chrisV (subscriber, #43417)
[Link]
I agree. And if you get false sharing between two free-standing variables where the one being operated on is marked volatile, or between fields of a struct where the struct is marked volatile, there is a compiler bug. It is still not clear whether that is the case with the kernel test case (first, the struct was not marked volatile, only one of its fields; and secondly, we don't know whether the test case involved an asynchronous test (as opposed to threads) or not.
Betrayed by a bitfield
Posted Feb 7, 2012 20:01 UTC (Tue) by dlang (✭ supporter ✭, #313)
[Link]
the kernel did not have one field marked volatile, but in the research into the problem, someone (I think it was Linus) tested with volatile and the false sharing was happening there as well.
Betrayed by a bitfield
Posted Feb 7, 2012 23:32 UTC (Tue) by daglwn (subscriber, #65432)
[Link]
> And if you get false sharing between two free-standing variables where the > one being operated on is marked volatile, or between fields of a struct
> where the struct is marked volatile, there is a compiler bug.
No, there isn't.
There isn't. Really.
Volatile does not mean what you think it means.
It's a bit like sequential consistency. Just when you think you understand it, something unexpected happens that is both non-intuitive and perfectly legal.
Betrayed by a bitfield
Posted Feb 8, 2012 15:24 UTC (Wed) by daglwn (subscriber, #65432)
[Link]
Seeing some of your other posts about -pthread, I think we are in agreement. Apologies if I mischaracterized your understanding.
Betrayed by a bitfield
Posted Feb 8, 2012 13:51 UTC (Wed) by nix (subscriber, #2304)
[Link]