rise-lang / shine

The Shine compiler for the RISE language
https://rise-lang.org
MIT License
73 stars 8 forks source link

[BUG] runWithTimeout does not kill the running thread, only returns to host program #193

Open johanneslenfers opened 3 years ago

johanneslenfers commented 3 years ago

Describe the bug Function runWithTimeout does not kill the running thread. It only returns to host program. The thread stays running in the background.

  // WARNING: does not kill the thread, we only return to host program
  // Thread.stop() is deprecated and cannot be used here
  // add option to stop thread in unsafe way
  def runWithTimeout[T](timeoutMs: Long)(f: => T) : Option[T] = {
    try {
      val executor = Executors.newSingleThreadExecutor()
      val res = executor.invokeAll(java.util.Arrays.asList(new java.util.concurrent.Callable[T] {
        override def call(): T = f
      }), timeoutMs, TimeUnit.MILLISECONDS)
      executor.shutdown()
      Some(res.get(0).get())
    } catch {
      case _: TimeoutException => None
      case _: java.util.concurrent.CancellationException => None
    }
  }

To Reproduce Execute test generate huge amount of code (line 568) in autotuning.scala

Expected behavior Code generation would create opencl kernel file bigger than 150MB. Function is timed out after 5 seconds. Code generation will continue in the background.

Possible solution Stop thread in an unsafe way.