[concurrency-interest] Happens before relation between a static write and a read?

Peter Veentjer alarmnummer at gmail.com
Tue Feb 12 12:51:03 EST 2008


I have a question regarding a happens before relation.

Let me show you the example:

class Foo{

     private static Map somemap = new HashMap();

     public void bar(){
          somemap.put("a","b");
     }
}

Is there a happens before relation of the write of somemap and the
read in the bar method? My guess would be that there is no direct
visible happens before relation, so in theory this example contains a
data race. Is this assumption correct? I can imagine that in practice
there is no problem because on a higher level some kind happens before
relation is added (maybe the thread that loads the class, also starts
the thread that executes the run methd, so  -> Thread.start happens
before rule).


More information about the Concurrency-interest mailing list