further attempts to simplify/robustify Swing_Thread.now, to avoid spurious physical race conditions on Java 6 / Mac OS X;
authorwenzelm
Fri, 25 May 2012 13:19:10 +0200
changeset 48000 880f1693299a
parent 47999 3ffd885abe00
child 48001 c79adcae9869
further attempts to simplify/robustify Swing_Thread.now, to avoid spurious physical race conditions on Java 6 / Mac OS X;
src/Pure/System/swing_thread.scala
--- a/src/Pure/System/swing_thread.scala	Fri May 25 11:18:32 2012 +0200
+++ b/src/Pure/System/swing_thread.scala	Fri May 25 13:19:10 2012 +0200
@@ -24,11 +24,12 @@
 
   def now[A](body: => A): A =
   {
-    @volatile var result: Option[Exn.Result[A]] = None
-    if (SwingUtilities.isEventDispatchThread()) { result = Some(Exn.capture(body)) }
-    else
-      SwingUtilities.invokeAndWait(new Runnable { def run = { result = Some(Exn.capture(body)) } })
-    Exn.release(result.get)
+    if (SwingUtilities.isEventDispatchThread()) body
+    else {
+      lazy val result = { assert(); Exn.capture(body) }
+      SwingUtilities.invokeAndWait(new Runnable { def run = result })
+      Exn.release(result)
+    }
   }
 
   def future[A](body: => A): Future[A] =