Scala and the Java Memory Model

Posted by Ben Lings on Stack Overflow See other posts from Stack Overflow or by Ben Lings
Published on 2010-03-17T12:55:11Z Indexed on 2010/03/17 13:01 UTC
Read the original article Hit count: 312

The Java Memory Model (since 1.5) treats final fields differently to non-final fields. In particular, provided the this reference doesn't escape during construction, writes to final fields in the constructor are guaranteed to be visible on other threads even if the object is made available to the other thread via a data race. (Writes to non-final fields aren't guaranteed to be visible, so if you improperly publish them, another thread could see them in a partially constructed state.)

Is there any documentation on how/if the Scala compiler creates final (rather than non-final) backing fields for classes? I've looked through the language specification and searched the web but can't find any definitive answers. (In comparison the @scala.volatile annotation is documented to mark a field as volatile)

© Stack Overflow or respective owner

Related posts about scala

Related posts about concurrency