News for hackers. Stuff that matters.
Re:Java Memory Model Pragmatics by zmmmmm on Friday July 11, 2014 @10:01PM (#8023462)
The memory model seems to be the real achilles heel for concurrency in Java. In the end with a only little bit of work one can master the concurrency primitives and they are quite usable. However understanding the full ramifications of the memory model is pretty much beyond mere mortals. As a result it is hard to do anything else than stick to established patterns and / or toolkits and frameworks if you don't want to set yourself up for insidious issues that are nearly impossible to reproduce.
Re:Java Memory Model Pragmatics by noelwelsh on Saturday July 12, 2014 @02:18AM (#8023854)
Au contraire, the fact that Java actually has a memory model means one can reason about concurrency in a way impossible on other platforms.

As you note you rarely need to concern yourself with the details of the memory model as most of us are users, not designers, of concurrency primitives. But you should you need to design a new primitive you can actually have some guarantees it will work in a cross-platform manner, which is more than you an say about any other platform I know of.

Re:Java Memory Model Pragmatics by zmmmmm on Saturday July 12, 2014 @06:44AM (#8024210)
Very true!

Having it defined is very important. However part of the problem is that definition actually takes away guarantees that many CPUs (eg. x86) give you. For example double checked locking works in x86 but famously not in Java. So the fact is that Java is giving you in some ways a less sequential model than what you started with is what makes it particularly insidious.

Re:Java Memory Model Pragmatics by pron on Saturday July 12, 2014 @09:16AM (#8024453)
You are free to rely on the guarantees made by a particular hardware architecture. The JVM implementation doesn't "take them away" -- the spec merely doesn't guarantee them. But if you do, then you might lose portability.
Re:Java Memory Model Pragmatics by zmmmmm on Saturday July 12, 2014 @06:58PM (#8026037)
My impression is that by not guaranteeing them it does take them away, because the implementation is free to implement them in any way they choose including in the compiler. So it will not matter if your code is executing on a processor that does not reorder instructions, Javac may already have done it to the byte code.
Re:Java Memory Model Pragmatics by pron on Monday July 14, 2014 @04:19PM (#8032970)
Even a C compiler is allowed to reorder instructions. How is any compiler supposed to know if you prefer performance (and therefore reordering) or to to rely on a processor-specific feature? That's why any language that runs on more than one architecture needs to define a language-level memory model.
Re:Java Memory Model Pragmatics by nradov on Saturday July 12, 2014 @10:04AM (#8024564)
Double checked locking works correctly in Java since version 1.5.
Re:Java Memory Model Pragmatics by fiatmoney on Saturday July 12, 2014 @01:12AM (#8023770)
The memory model is actually relatively straightforward on the user side; it's significantly more complicated on the implementer side.

In most cases you can get away with coarser constructs (which are higher-performing anyway, eg task parallelism vs. trying to decompose an individual operation) and only dive into the language lawyering semantics when you, eg, really really need a lockfree concurrent linked list.

Re:Java Memory Model Pragmatics by pcwalton on Friday July 11, 2014 @10:06PM (#8023470)
> The memory model seems to be the real achilles heel for concurrency in Java.

I'd expand it beyond Java to shared-everything models in general. Any language with a shared-everything model is going to incur all this complexity. At least Java goes through this pain to ensure memory safety in the presence of unsynchronized accesses from multiple threads.

Re:Java Memory Model Pragmatics by mushishi on Saturday July 12, 2014 @04:27AM (#8024022)
So how do you deal with non-Java platforms? Do you use only those that have memory model defined?