[Interest] Heavily Commented Example: Simple Single Frontend with Two Backends
Jan Kundrát
jkt at flaska.net
Mon Oct 22 15:51:28 CEST 2012
On 10/22/12 14:16, Bo Thorsen wrote:
> Not correct. Neither the compiler nor the CPU can reorder around a volatile.
Hi Bo,
various sources which I've read about this topic (like [1], [2], [3],
[4]) disagree. I might be wrong and would like to be corrected in that
case -- references are welcome.
What I'm saying is that volatile is *not* intended to be used this way.
If you want to have a boolean variable which is safe to be accessed
across threads, just use the QAtomicInt class [4]. I haven't made a
benchmark in the "hi thread, please die" case so I have no data on what
its overhead on the mainstream platforms is.
Cheers,
Jan
[1] Herb Sutter's statement: "one reading of the standard is that
ordinary loads may be reordered across a volatile load or store, but not
ordinary writes" at
http://www.drdobbs.com/parallel/volatile-vs-volatile/212701484
[2] http://msdn.microsoft.com/en-us/library/12a04hfd.aspx
[3]
http://stackoverflow.com/questions/2535148/volatile-qualifier-and-compiler-reorderings
[4]
http://stackoverflow.com/questions/2484980/why-is-volatile-not-considered-useful-in-multithreaded-c-or-c-programming
[5] http://qt-project.org/doc/qt-4.8/atomic-operations.html
--
Trojita, a fast e-mail client -- http://trojita.flaska.net/
More information about the Interest
mailing list