restricted interrupts for tasks running as future worker thread -- attempt to prevent interrupt race conditions;
authorwenzelm
Sat, 21 Mar 2009 13:11:12 +0100
changeset 30618 046f4f986fb5
parent 30617 620db300c038
child 30619 0226c07352db
restricted interrupts for tasks running as future worker thread -- attempt to prevent interrupt race conditions;
src/Pure/Concurrent/future.ML
src/Pure/Isar/toplevel.ML
--- a/src/Pure/Concurrent/future.ML	Sat Mar 21 12:37:13 2009 +0100
+++ b/src/Pure/Concurrent/future.ML	Sat Mar 21 13:11:12 2009 +0100
@@ -44,6 +44,7 @@
   val join_result: 'a future -> 'a Exn.result
   val join: 'a future -> 'a
   val map: ('a -> 'b) -> 'a future -> 'b future
+  val interruptible_task: ('a -> 'b) -> 'a -> 'b
   val interrupt_task: string -> unit
   val cancel_group: group -> unit
   val cancel: 'a future -> unit
@@ -350,6 +351,15 @@
 
 (* cancellation *)
 
+fun interruptible_task f x =
+  if Multithreading.available then
+    Multithreading.with_attributes
+      (if is_some (thread_data ())
+       then Multithreading.restricted_interrupts
+       else Multithreading.regular_interrupts)
+      (fn _ => f) x
+  else interruptible f x;
+
 (*interrupt: permissive signal, may get ignored*)
 fun interrupt_task id = SYNCHRONIZED "interrupt"
   (fn () => Task_Queue.interrupt_external (! queue) id);
--- a/src/Pure/Isar/toplevel.ML	Sat Mar 21 12:37:13 2009 +0100
+++ b/src/Pure/Isar/toplevel.ML	Sat Mar 21 13:11:12 2009 +0100
@@ -311,7 +311,7 @@
 fun controlled_execution f =
   f
   |> debugging
-  |> interruptible;
+  |> Future.interruptible_task;
 
 fun program f =
  (f