New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream is not thread-safe #3515
Comments
Imported From: https://issues.scala-lang.org/browse/SI-3515?orig=1 |
@oschulz said: def tailDefined: Boolean = tailDefinedVar
@volatile protected var tailDefinedVar = false
override lazy val tail: Stream[A] = { tailDefinedVar = true; tl } to keep the public interface immutable. |
@paulp said: |
@oschulz said: I'll understand if this change goes to deep this late in the RC phase, though. |
Reason: In the definition of collection.immutable.Stream.Cons
there is no locking meachanism, and tl may be executed
multiple times for the same position in the Stream.
Demonstration: The following script
Produces an output like this:
Proposed solution: Make tail a lazy val, e.g. like this
Demo:
produces something like this:
While Stream is not specified to be thread-safe in the API docs, Scala's
immutable collections are usually expected to be (since inherent
thread-safety is one of their major strengths). So i propose to classify
this as a defect.
I'd vote to include this in 2.8.0.RC4, if accepted.
System information, for completeness:
The text was updated successfully, but these errors were encountered: