top | item 8022251

Java Memory Model Pragmatics

108 points| t__crayford | 11 years ago |shipilev.net | reply

21 comments

order
[+] theocs|11 years ago|reply
This is very technical, most likely way past what 99% of developers both need to care about and have to care about.

Given that most developers work at best with embarrassingly parallel problems they wouldn't need to know much of these details.

But if you're up for it: It's a very rewarding feeling when you're both allowed to figure these things out and someone are also paying you while you figure it out.

[+] mahmud|11 years ago|reply
Who cares about "most developers". This is interesting for its own sake.
[+] virmundi|11 years ago|reply
In the section about nasal demons, did anyone else think the right answer was 12 too? I figured the parens make the context local so the ++ had to occur after the add.
[+] aeonsky|11 years ago|reply
There is no right answer to that problem.
[+] marcosscriven|11 years ago|reply
Just an FYI - 'select over' doesn't work on iOS Safari.
[+] josephlord|11 years ago|reply
Copy and paste to notes was my work around.
[+] zmmmmm|11 years ago|reply
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.
[+] noelwelsh|11 years ago|reply
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.

[+] fiatmoney|11 years ago|reply
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.

[+] pcwalton|11 years ago|reply
> 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.

[+] mushishi|11 years ago|reply
So how do you deal with non-Java platforms? Do you use only those that have memory model defined?