This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve 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]

FYi: TimerWatcher race fix


Hi,

I found a race in the TimerWatcher. It has an isAlive() method and the
runTest() method would check that to see whether to start() or reset()
it. Since there is a small window where isAlive() could return false,
but the Thread was already started I made reset() do the check itself.
2006-07-07  Mark Wielaard  <mark@klomp.org>

	* Harness.java (runTest): Just reset runner_watcher.
	(TimerWatcher.started): New boolean field.
	(TimerWatcher.start): Removed method.
	(TimerWatcher.isAlive): Removed method.
	(reset): Start Thread if not yet started.

Committed,

Mark
Index: Harness.java
===================================================================
RCS file: /cvs/mauve/mauve/Harness.java,v
retrieving revision 1.19
diff -u -r1.19 Harness.java
--- Harness.java	5 Jul 2006 17:45:51 -0000	1.19
+++ Harness.java	9 Jul 2006 17:50:31 -0000
@@ -751,11 +751,8 @@
     	runner_esp = new ErrorStreamPrinter(runnerProcess.getErrorStream());
     }
 
-    // Start the timeout watcher
-    if (runner_watcher.isAlive())
-      runner_watcher.reset();
-    else
-      runner_watcher.start();
+    // (Re)start the timeout watcher
+    runner_watcher.reset();
     
     // Tell the RunnerProcess to run test with name testName
     runner_out.println(testName);
@@ -1148,6 +1145,7 @@
   {
     private long millisToWait;
     private Thread watcherThread;
+    private boolean started;
     private boolean loop = true;
     private boolean shouldContinue = true;
     
@@ -1163,18 +1161,11 @@
     {
       millisToWait = millis;
       watcherThread = new Thread(this);
+      started = false;
       this.runnerProcess = runnerProcess;
     }
     
     /**
-     * Start the watcher thread, ie start the countdown.     
-     */
-    public void start()
-    {
-      watcherThread.start();      
-    }
-    
-    /**
      * Stops the run() method.
      *
      */
@@ -1185,22 +1176,21 @@
     }
     
     /**
-     * Return true if the watcher thread is currently counting down.
-     * @return true if the watcher thread is alive
-     */
-    public boolean isAlive()
-    {
-      return watcherThread.isAlive();
-    }
-    
-    /**
      * Reset the counter and wait another <code>millisToWait</code>
-     * milliseconds before declaring the test as hung.     
+     * milliseconds before declaring the test as hung.
      */
     public synchronized void reset()
     {
-      loop = true;
-      notify();
+      if (!started)
+        {
+	  watcherThread.start();
+	  started = true;
+	}
+      else
+        {
+	  loop = true;
+	  notify();
+        }
     }
     
     public synchronized void run()

Attachment: signature.asc
Description: This is a digitally signed message part


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