3

Scala noob here: val pv = (1 to 100).toArray.par

Now I want to apply a map function to this parallel collection pv

pv.map(_ * 2)

However the above operation hangs. Any reason why?

Using Scala version 2.12.4 on a Mac OS X (High Sierra)

Javiar Sandra
  • 827
  • 1
  • 10
  • 25

1 Answers1

5

Seems this is caused by static initializer deadlock, see:

https://github.com/scala/scala-parallel-collections/issues/34

This issue point out in the repl, when create a parallel collection, repl will generate a wraper for it, when init, it will cause dead lock.

and it also can be reproduce in program from the:

https://github.com/scala/bug/issues/8119

object Foreacher {
  val n = 0
  val m = List(1).par.foreach(_ => n)
  def main(args: Array[String]): Unit = println("Hello, all")
}
chengpohi
  • 14,064
  • 1
  • 24
  • 42
  • 2
    In particular see the other Stack Overflow answer linked in the GitHub issue: [https://stackoverflow.com/questions/15176199/scala-parallel-collection-in-object-initializer-causes-a-program-to-hang/15176433#15176433](https://stackoverflow.com/questions/15176199/scala-parallel-collection-in-object-initializer-causes-a-program-to-hang/15176433#15176433) – badcook Dec 07 '17 at 02:13