This is the mail archive of the
frysk@sourceware.org
mailing list for the frysk project.
Re: [SCM] master: Avoid spurious waits in CountDownLatch.await
- From: Mark Wielaard <mark at klomp dot org>
- To: frysk at sourceware dot org
- Cc: Tim Moore <timoore at redhat dot com>
- Date: Fri, 23 Nov 2007 12:14:57 +0100
- Subject: Re: [SCM] master: Avoid spurious waits in CountDownLatch.await
- References: <20071122205327.10260.qmail@sourceware.org> <1195810857.2981.6.camel@dijkstra.wildebeest.org>
Hi Tim,
On Fri, 2007-11-23 at 10:40 +0100, Mark Wielaard wrote:
> On Thu, 2007-11-22 at 20:53 +0000, moore@sourceware.org wrote:
> > 2007-11-22 Tim Moore <timoore@redhat.com>
> >
> > * CountDownLatch.java (await): Loop to avoid spurious wakeup.
>
> Using wait() and notify() are such a pain :{
> Good you caught this one.
> Using higher order concurrent primitives is good.
I did find a bug though (just by running make check in frysk-core).
await need to be synchronized if you call wait() on this otherwise you
will get "current thread not owner" exceptions.
You might want to look into the public domain implementation of
CountDownLatch maybe to double check you got all the corner cases:
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/CountDownLatch.java
Cheers,
Mark
diff --git a/frysk-core/frysk/util/CountDownLatch.java
b/frysk-core/frysk/util/C
index b191782..f9d548f 100644
--- a/frysk-core/frysk/util/CountDownLatch.java
+++ b/frysk-core/frysk/util/CountDownLatch.java
@@ -53,7 +53,7 @@ public class CountDownLatch {
this.count = count;
}
- public void await()
+ public synchronized void await()
throws InterruptedException {
while (count != 0) {
try {