This is the mail archive of the frysk@sourceware.org mailing list for the frysk 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: [SCM] master: Avoid spurious waits in CountDownLatch.await


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 {



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