src/Pure/System/posix_interrupt.scala
changeset 56860 dc71c3d0e909
parent 51250 ca13a14cc52e
child 59720 f893472fff31
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/System/posix_interrupt.scala	Mon May 05 09:24:34 2014 +0200
@@ -0,0 +1,29 @@
+/*  Title:      Pure/System/interrupt.scala
+    Author:     Makarius
+
+Support for POSIX interrupts (bypassed on Windows).
+*/
+
+package isabelle
+
+
+import sun.misc.{Signal, SignalHandler}
+
+
+object POSIX_Interrupt
+{
+  def handler[A](h: => Unit)(e: => A): A =
+  {
+    val SIGINT = new Signal("INT")
+    val new_handler = new SignalHandler { def handle(s: Signal) { h } }
+    val old_handler = Signal.handle(SIGINT, new_handler)
+    try { e } finally { Signal.handle(SIGINT, old_handler) }
+  }
+
+  def exception[A](e: => A): A =
+  {
+    val thread = Thread.currentThread
+    handler { thread.interrupt } { e }
+  }
+}
+