summaryrefslogtreecommitdiff
path: root/test/files/run/testblock.scala
blob: a334b668fdedefbf1dbd5d7b8e64f17f62461231 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import scala.parallel._




object Test {

  def main(args: Array[String]) {
    if (util.Properties.isJavaAtLeast("1.6")) {
      val vendor = util.Properties.javaVmVendor
      if ((vendor contains "Sun") || (vendor contains "Apple")) blockcomp(10)
    }
  }

  val lock = new java.util.concurrent.locks.ReentrantLock

  def blockcomp(n: Int): Unit = if (n > 0) {
    val (x, y) = par(blockcomp(n - 1), blockcomp(n - 1))
    if (n == 8) blocking { // without this blocking block, deadlock occurs
      lock.lock()
    }
    x()
    y()
    if (n == 8) {
      lock.unlock()
    }
  }

}