Are Java pointer writes atomic?

atomic, java, multithreading, synchronization, thread-safety

Solution

Reads and writes are atomic for reference variables.

Source: http://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html

Problem

Simple question: does the Java memory/synchronization model guarantee atomic pointer writes? That is, if we have competing threads: ``` String shared; thread1() { shared = "a"; } thread2() { shared = "hello world"; } ``` started at the same time, is `shared` always guaranteed to be `null`, `"a"`, or `"hello world"`?

Original source