Example usage @threadUnsafe annotation
Teinnsei opened this issue · 2 comments
Teinnsei commented
Hi everyone.
This project include example to use lazy val
field. In new proposal to Scala project have changed implementation of lazy val
.
/**
* In order to get thread safety, you need to put @volatile before lazy vals.
* https://dotty.epfl.ch/docs/reference/changed-features/lazy-vals-init.html
*/
@volatile lazy val xs: List[String] = List("d", "o", "t", "t", "y")
As I understood to safe thread-safe sematics we need to attach @volatile annotation to lazy val
field.
Dotty/Scala3 in std have scala.annotation.threadUnsafe
annotation also. Is it still actual annotation? And if it is true in wich cases we need to use this annotation. Can you please add example?
Thank you
SethTisue commented
iirc, early Dotty versions had thread-unsafe lazy val
s. but at some point the design changed and it was decided to make thread-safety the default again, as in Scala 2. so yeah, a fix is needed here.
Teinnsei commented
Thank you for your explanation.