[concurrency-interest] Relativity of guarantees provided by volatile
mtopolnik at inge-mark.hr
Sat Aug 18 04:44:44 EDT 2012
On 18. kol. 2012., at 10:24, Yuval Shavit wrote:
> On Sat, Aug 18, 2012 at 3:35 AM, Marko Topolnik <mtopolnik at inge-mark.hr> wrote:
> However, what is troubling is the belief of practically every developer out there that there's a hard realtime GUARANTEE of the instantaneous visibility of volatile writes.
> Do they? I certainly believe that the read is going to see the write very quickly, but a hard, realtime guarantee? Between the JIT, GC and other apps that may hog CPU, I don't even depend on a realtime guarantee between "int i = 5" and "i++".
Yes, my wording was too strong. I didn't mean "hard realtime", but a hard guarantee, as opposed to a soft promise of best effort. The volatile modifier gives you two things: a hard guarantee of proper observed ordering of actions, and a *hint* towards the timely publishing of a write. This is where confusion enters---take this typical argument: "Without the volatile modifier the reading thread is not guaranteed to ever observe a write to the var". Well guess what, with the modifier it still isn't *guaranteed* to ever observe it. This fact is very counterintuitive and many people would even religiously oppose it. I cannot escape the troubling feeling this gives me---a developer should have the right intuition about his code and shouldn't shake his head in disbelief when shown any piece of code and the output that code may legally produce. Somewhere down the line this must matter.
More information about the Concurrency-interest