This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: (scheme-window)


I've appended a suggested patch.  Does this work?
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/
Index: kawa/repl.java
===================================================================
RCS file: /cvs/kawa/kawa/kawa/repl.java,v
retrieving revision 1.45
diff -u -r1.45 repl.java
--- kawa/repl.java	13 Feb 2002 22:20:26 -0000	1.45
+++ kawa/repl.java	17 Apr 2002 19:53:40 -0000
@@ -90,6 +90,35 @@
     out.println("For more information go to:  http://www.gnu.org/software/kawa/";);
   }
 
+  /** Number of times exitDecrement calls before we exit. */
+  private static int exitCounter;
+  public static synchronized void exitIncrement()
+  {
+    if (exitCounter == 0)
+      exitCounter++;
+    exitCounter++;
+  }
+
+  /** Work around an AWT bug, where AWT threads are non-daemon.
+   * Thus if you start up AWT, the JVM will wait for the AWT to finish,
+   * even if there are no other non-daemon threads.
+   * So call exitIncrement() each time a Freme is created,
+   * and call exitDecrement() a Frame is closed. */
+  public static synchronized void exitDecrement()
+  {
+    int counter = exitCounter;
+    if (counter > 0)
+      {
+	counter--;
+	if (counter == 0)
+	  {
+	    System.exit(0);
+	  }
+	else
+	  exitCounter = counter;
+      }
+  }
+
   public static FVector commandLineArguments;
 
   public static String homeDirectory;
@@ -158,7 +187,6 @@
 
   static boolean shutdownRegistered
     = gnu.text.WriterManager.instance.registerShutdownHook();
-  static boolean windowStarted = false;
 
   public static int processArgs(String[] args, int iArg, int maxArg)
   {
@@ -303,7 +331,6 @@
 	    try
 	      {
 		Class.forName("kawa.GuiConsole").newInstance();
-		windowStarted = true;
 	      }
 	    catch (Exception ex)
 	      {
@@ -563,11 +590,12 @@
       }
     finally
       {
-	if (! shutdownRegistered && ! windowStarted)
+	if (! shutdownRegistered)
 	  {
 	    // Redundant if registerShutdownHook succeeded (e.g on JDK 1.3).
 	    gnu.mapping.OutPort.runCleanups();
 	  }
+	exitDecrement();
       }
    }
 
Index: kawa/GuiConsole.java
===================================================================
RCS file: /cvs/kawa/kawa/kawa/GuiConsole.java,v
retrieving revision 1.13
diff -u -r1.13 GuiConsole.java
--- kawa/GuiConsole.java	18 Aug 2000 02:33:01 -0000	1.13
+++ kawa/GuiConsole.java	17 Apr 2002 19:53:40 -0000
@@ -22,8 +22,6 @@
 
   static int window_number = 0;
 
-  public static int numConsoles = 0;
-
   Interpreter interp;
   Environment environment;
   Future thread;
@@ -51,7 +49,7 @@
     in_r = new gnu.text.QueueReader ();
     message = new MessageArea(false, in_r);
     window_number++;
-    numConsoles++;
+    kawa.repl.exitIncrement();
 
     out_p = new OutPort(message.getStdout(), true, "<msg_stdout>");
     err_p = new OutPort(message.getStderr(), true, "<msg_stderr>");
@@ -74,19 +72,17 @@
 
   void close () {
     in_r.appendEOF();
-    numConsoles--;
     dispose();
     // Give thread chance to finish and clean up
     try {
       Thread.sleep(100);
     } catch (InterruptedException ex) {
     }
-    if (numConsoles <= 0)
-      System.exit(0);
     // Thread.stop is deprecated in JDK 1.2, but I see no good
     // alternative.  (Thread.destroy is not implemented!)
-    thread.stop();
-  }
+    thread.stop(); 
+    kawa.repl.exitDecrement();
+ }
 
   private void setupMenus() {
     MenuBar menubar;
Index: gnu/expr/ModuleBody.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/expr/ModuleBody.java,v
retrieving revision 1.18
diff -u -r1.18 ModuleBody.java
--- gnu/expr/ModuleBody.java	13 Feb 2002 22:16:06 -0000	1.18
+++ gnu/expr/ModuleBody.java	17 Apr 2002 19:53:40 -0000
@@ -94,6 +94,7 @@
 	  }
 	// Redundant if registerShutdownHook succeeded (e.g on JDK 1.3).
 	gnu.mapping.OutPort.runCleanups();
+	kawa.repl.exitDecrement();
       }
     catch (Throwable ex)
       {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]