[concurrency-interest] Joda-Time immutability

Boehm, Hans hans.boehm at hp.com
Tue Aug 2 14:51:23 EDT 2011

Volatile loads should be cheap on x86.  Volatile stores involve an explicit fence or XCHG operation.  In my experience, this costs somewhere between a dozen and hundreds of cycles, depending on the particular processor, and context.  The (now essentially obsolete) Pentium 4 generation of Intel processors seemed to have the highest costs, often by a wide margin.

My intuition is that this usually doesn't matter too much, since:

1) Loads tend to be more frequent than stores, and
2) If stores are frequent and executed by multiple threads, you are likely to spend even more time dealing with coherence misses.

It may well be that neither observation applies here.

(There is also an argument that much of these costs should be avoidable by adding a couple of instructions that essentially perform volatile loads and stores.  The fence here is often substantial over-kill.  But it's the only hammer we currently have ...)


> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu [mailto:concurrency-
> interest-bounces at cs.oswego.edu] On Behalf Of Mark Thornton
> Sent: Monday, August 01, 2011 2:47 PM
> To: concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] Joda-Time immutability
> On 01/08/11 22:15, Shay Banon wrote:
> > I just did a quick test by changing to volatile field the 1.6
> release,
> > and on my machine I see 6x worse perf on 10 million data points (on a
> > "real world" use case in my system, end to end). Naturally, this will
> > vary depending on many aspects (number of cores, os) in terms of how
> > volatile write and read are handled. I really think that this is the
> > wrong solution to the "problem", but up to you...
> What sort of machine are you using? My impression was that volatile is
> quite cheap on x86.
> Mark Thornton
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list