summaryrefslogtreecommitdiff
path: root/test/files/run/lazy-concurrent.scala
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2010-06-09 15:49:53 +0000
committerIulian Dragos <jaguarul@gmail.com>2010-06-09 15:49:53 +0000
commitf8429e2fcd23ebfdb67203e86cf6002445c77a63 (patch)
treea78b797507da749fb26d800c200719037ef5fb8d /test/files/run/lazy-concurrent.scala
parent0f5d5c58ec964d8769e0d538efe5e4d14563fd0a (diff)
downloadscala-f8429e2fcd23ebfdb67203e86cf6002445c77a63.tar.gz
scala-f8429e2fcd23ebfdb67203e86cf6002445c77a63.tar.bz2
scala-f8429e2fcd23ebfdb67203e86cf6002445c77a63.zip
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.
Diffstat (limited to 'test/files/run/lazy-concurrent.scala')
-rw-r--r--test/files/run/lazy-concurrent.scala17
1 files changed, 17 insertions, 0 deletions
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
+ }
+ }
+}