From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28235 invoked by alias); 23 Nov 2007 11:15:08 -0000 Received: (qmail 28187 invoked by uid 22791); 23 Nov 2007 11:15:07 -0000 X-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,FORGED_RCVD_HELO,WLS_URI_OPT_0 X-Spam-Check-By: sourceware.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (83.160.170.119) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 23 Nov 2007 11:15:00 +0000 Received: from dijkstra.wildebeest.org ([192.168.1.29]) by gnu.wildebeest.org with esmtp (Exim 4.63) (envelope-from ) id 1IvWUr-0005uA-Mq; Fri, 23 Nov 2007 12:14:58 +0100 Subject: Re: [SCM] master: Avoid spurious waits in CountDownLatch.await From: Mark Wielaard To: frysk@sourceware.org Cc: Tim Moore In-Reply-To: <1195810857.2981.6.camel@dijkstra.wildebeest.org> References: <20071122205327.10260.qmail@sourceware.org> <1195810857.2981.6.camel@dijkstra.wildebeest.org> Content-Type: text/plain Date: Fri, 23 Nov 2007 11:15:00 -0000 Message-Id: <1195816497.2981.13.camel@dijkstra.wildebeest.org> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 (2.12.1-3.fc8) Content-Transfer-Encoding: 7bit X-Spam-Score: -1.4 (-) X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q4/txt/msg00168.txt.bz2 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 > > > > * 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 {