From f8429e2fcd23ebfdb67203e86cf6002445c77a63 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 9 Jun 2010 15:49:53 +0000 Subject: Make local lazy values thread-safe. is now guaranteed to be initialized at most once, even when accessed from different threads. Closes #3007, review by odersky. --- test/files/run/lazy-concurrent.check | 1 + test/files/run/lazy-concurrent.scala | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/files/run/lazy-concurrent.check create mode 100644 test/files/run/lazy-concurrent.scala (limited to 'test/files/run') diff --git a/test/files/run/lazy-concurrent.check b/test/files/run/lazy-concurrent.check new file mode 100644 index 0000000000..33cff9d4f8 --- /dev/null +++ b/test/files/run/lazy-concurrent.check @@ -0,0 +1 @@ +Initializing singleton. diff --git a/test/files/run/lazy-concurrent.scala b/test/files/run/lazy-concurrent.scala new file mode 100644 index 0000000000..4699ed6a15 --- /dev/null +++ b/test/files/run/lazy-concurrent.scala @@ -0,0 +1,17 @@ +object Test { + def main(args: Array[String]) { + class Singleton { + val field = () + println("Initializing singleton.") + } + lazy val Singleton = new Singleton + + var i = 0 + while (i < 4) { + new Thread(new Runnable { + def run = Singleton.field + }).start + i += 1 + } + } +} -- cgit v1.2.3