with_attributes: canonical capture/release scheme (potentially iron out race condition);
authorwenzelm
Fri, 20 Mar 2009 11:08:59 +0100
changeset 30602 1bd90b76477a
parent 30601 febd9234abdd
child 30603 71180005f251
with_attributes: canonical capture/release scheme (potentially iron out race condition);
src/Pure/ML-Systems/multithreading_polyml.ML
--- a/src/Pure/ML-Systems/multithreading_polyml.ML	Fri Mar 20 09:52:32 2009 +0100
+++ b/src/Pure/ML-Systems/multithreading_polyml.ML	Fri Mar 20 11:08:59 2009 +0100
@@ -77,11 +77,9 @@
 fun with_attributes new_atts f x =
   let
     val orig_atts = safe_interrupts (Thread.getAttributes ());
-    fun restore () = Thread.setAttributes orig_atts;
-    val result =
-      (Thread.setAttributes (safe_interrupts new_atts);
-        Exn.Result (f orig_atts x) before restore ())
-      handle e => Exn.Exn e before restore ();
+    val result = Exn.capture (fn () =>
+      (Thread.setAttributes (safe_interrupts new_atts); f orig_atts x)) ();
+    val _ = Thread.setAttributes orig_atts;
   in Exn.release result end;
 
 fun interruptible f = with_attributes regular_interrupts (fn _ => f);