RE: JavaMemoryModel: Thread starting in constructors

From: Jeremy Manson (jmanson@cs.umd.edu)
Date: Tue Mar 12 2002 - 00:05:47 EST


> > You know, all this makes me *very* uncomfortable. It *should* be safe
> > to publish "this" as the last action in a constructor.

I know this is taking your comment out of context, but wouldn't such a
restriction kill some optimizations? For example (warning - contrived
example) are you saying that in:

class Foo {
  final int i;
  static Foo f;
  public Foo () {
    Foo g;
    g = this;
    i = 2;
    f = g;
  }
}

Compilers can't transform that to:

public Foo() {
  f = this;
  i = 2;
}

because the original code has to be safe? Processors can't execute those
instructions out of order, either?

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



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