* FYi: TimerWatcher race fix
@ 2006-07-09 17:53 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2006-07-09 17:53 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1.1: Type: text/plain, Size: 589 bytes --]
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
[-- Attachment #1.2: patch --]
[-- Type: text/x-patch, Size: 2132 bytes --]
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 #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-07-09 17:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-09 17:53 FYi: TimerWatcher race fix Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).