RE: JavaMemoryModel: Question: Why is it that Memory Models are Intuitively Hard?

From: David Holmes (dholmes@dltech.com.au)
Date: Tue Feb 18 2003 - 18:01:10 EST


I think the basic rules of the memory model are very easy to
understand. Some things (like issues with final and immutable objects)
aren't easy to really understand, but easy to do correctly.

Most people, PhD or not, have no idea that they are even thinking in
sequentially consistent terms when writing multi-threaded code, let
alone understand the implications of not having sequential
consistency. This is something the hardware people foisted on us "for
our own good" and it's taken a while for people to realize just how
much it really hurts the programming models. People have been writing
unsafe non-portable MT C code for decades without realizing it.

Java at least tried to do the right thing by recognising that there
was a need for a memory model, but it turned out to be much much
harder than anyone (most of whom had PhD's I believe) thought to get
it "right". Java could have gotten out of this easy, like POSIX, by
not providing any guarantees for incorrectly synchronized programs,
and the memory model would have been trivial and this JSR wouldn't
have arisen. But language and type safety are important issues and so
the Java Memory Model has to provide guarantees that most other
systems don't have to care about: it is these things that have caused
the most pain in defining the memory model.

The other thing that has caused a lot of pain is those darn compiler
writers who keep insisting on "optimising" and messing with our
programs. :-)

Languages in which concurrency and synchronisation can't be done
incorrectly are still too immature for practical use today, but I
think their day will come eventually. But that day can only come if
people realize the contribution that such languages make, and the
problems that they solve. As long as we still have thousands of
programmers who are ignorant of memory model issues, we'll never
convince them that they really need one of these safe languages. So
meanwhile we have Java, with a more robust memory model, making it
easier to do the right thing and at least showing people that these
issues do exist.

Just my 2c.

David Holmes

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:42 EDT