diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2010-09-02 13:15:21 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2010-09-02 13:15:21 +0000 |
commit | 93fe8b8d9252297652d85d7f51965daa657676aa (patch) | |
tree | 5884cbbfd1dfd5d2ad75471483d012b0eb794079 /src/library | |
parent | 21af53483f83d91e69fec7097ecbe9e1524ca30c (diff) | |
download | scala-93fe8b8d9252297652d85d7f51965daa657676aa.tar.gz scala-93fe8b8d9252297652d85d7f51965daa657676aa.tar.bz2 scala-93fe8b8d9252297652d85d7f51965daa657676aa.zip |
Merged revisions 22897 via svnmerge from
https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk
........
r22897 | dragos | 2010-09-01 18:01:59 +0200 (Wed, 01 Sep 2010) | 1 line
Closes #1220. Stream.tail is now thread safe. Review by odersky.
........
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/immutable/Stream.scala | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 7660a1e2c8..40f71aa845 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -557,10 +557,14 @@ object Stream extends SeqFactory[Stream] { final class Cons[+A](hd: A, tl: => Stream[A]) extends Stream[A] { override def isEmpty = false override def head = hd - private[this] var tlVal: Stream[A] = _ - def tailDefined = tlVal ne null + @volatile private[this] var tlVal: Stream[A] = _ + def tailDefined: Boolean = tlVal ne null override def tail: Stream[A] = { - if (!tailDefined) { tlVal = tl } + if (!tailDefined) + synchronized { + if (!tailDefined) tlVal = tl + } + tlVal } } |