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

parallel collections + object initialization = hang #8119

Closed
scabug opened this Issue Jan 7, 2014 · 7 comments

Comments

Projects
None yet
1 participant
@scabug
Copy link

scabug commented Jan 7, 2014

This little poison pill:

val n = 0; for(i <- List(1).par) n

hangs the REPL in 2.9.3, 2.10.3, and 2.11.0-M7.

-Yrepl-sync doesn't help.

The collection type doesn't matter (List, Range, Vector, whatever).

Accessing n in the body is necessary.

Using semicolon to put it all on one line is necessary.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 7, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8119?orig=1
Reporter: @SethTisue
Affected Versions: 2.9.3, 2.10.3, 2.11.0-M7

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 7, 2014

@som-snytt said (edited on Jan 7, 2014 4:10:41 AM UTC):
This is not REPL-specific.

object Foreacher {
  val n = 0
  val m = List(1).par.foreach(_ => n)
  def main(args: Array[String]): Unit = println("Hello, all")
}

I guess the foreach is kicked off from the static initializer of the class and blocks on the par result, which is blocked in turn because it references the static module.

Of course, the REPL-specific part is the code wrapper. Put it in braces to localize it.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 7, 2014

@SethTisue said:
Hmm. I'm not sure whether to remove "REPL" from the "Components" list, since one could imagine fixing this in the REPL without fixing it generally. Not sure how much hope there is for either kind of fix, as I see now that the issue is pretty fundamental.

For whatever it's worth, I encountered this while pasting in code from a blog post titled "More Benefits of Scala in CS1" (http://dynamicsofprogramming.blogspot.com/2013/12/more-benefits-of-scala-in-cs1.html). I wouldn't want to have to explain/defend this to a beginner.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 7, 2014

@som-snytt said:

apm@mara:~$ scalam -Yrepl-class-based
Welcome to Scala version 2.11.0-M7 (OpenJDK 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val n = 0; for(i <- List(1).par) n
n: Int = 0
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 7, 2014

@SethTisue said:
Nice! I wasn't aware of scala/scala#3123 . Is there an issue or mailing list thread or something that explains the motivation for it...?

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 8, 2014

@som-snytt said:
"More details" link at the issue #7747.

@scabug scabug closed this Jun 7, 2015

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 3, 2015

@SethTisue said:
there is a nice writeup on this by @axel22 at http://stackoverflow.com/a/15176433/86485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment