It is not quite that simple. It also depends on what data.setValue
and data.getValue
actually do under the covers. Are those methods safe for concurrent (unsynchronized) calls?
In one contrived example, if data were backed by a HashMap
and multiple threads call various set methods concurrently, it could lead to an infinite loop.
In short, you are only able to guarantee the order of execution. You have some limited guarantees to memory visibility between the set and get, but not concurrent calls to set or get having any potential side effects.