public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* Re: [SCM]  master: Avoid spurious waits in CountDownLatch.await
       [not found] <20071122205327.10260.qmail@sourceware.org>
@ 2007-11-23  9:41 ` Mark Wielaard
  2007-11-23 11:15   ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2007-11-23  9:41 UTC (permalink / raw)
  To: frysk; +Cc: Tim Moore

Hi Tim,

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.

There are some other non-guarded wait()s in some of the stepping command
(StepInstructionCommand, StepNextCommand, StepNextiCommand), which all
have something like:

      synchronized (cli.steppingObserver.getMonitor())
        {
          try
            {
              //XXX This looks racy.
              cli.steppingObserver.getMonitor().wait();
            }
          catch (InterruptedException ie) {}
        }

The XXX comment is right :{

If you are cleaning this up anyway you might want to abstract away all
the logic about guarding the mutex into the steppingObserver.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [SCM]  master: Avoid spurious waits in CountDownLatch.await
  2007-11-23  9:41 ` [SCM] master: Avoid spurious waits in CountDownLatch.await Mark Wielaard
@ 2007-11-23 11:15   ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2007-11-23 11:15 UTC (permalink / raw)
  To: frysk; +Cc: Tim Moore

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 {


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-23 11:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20071122205327.10260.qmail@sourceware.org>
2007-11-23  9:41 ` [SCM] master: Avoid spurious waits in CountDownLatch.await Mark Wielaard
2007-11-23 11:15   ` 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).