This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

[gui] [PATCH] Fix to MediaTracker.imageUpdate()


Hi,

I committed the following patch to the java-gui-branch.  It fixes a
deadlock problem that was caused by MediaTracker.imageUpdate().  In that
method, we only want to notify waiting threads if the image has finished
loading.  If we prematurely notify a waiting thread, deadlocks can
occur.  Specifically, in MediaTracker.waitForAll(), there is a wait()
inside a synchronized block which will not exit until the image has
finished loading.  Notifying this waiting thread before the image is
complete will cause a deadlock, because waitForAll() will block the
image loading thread from completing, and waitForAll() will not exit the
synchronized block until the image has finished loading.

-David Jee

2004-06-10  David Jee  <djee@redhat.com>

        * java/awt/MediaTracker.java
        (imageUpdate): Only do notifyAll() if the image is complete.


Index: java/awt/MediaTracker.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/MediaTracker.java,v
retrieving revision 1.5.10.1
diff -u -r1.5.10.1 MediaTracker.java
--- java/awt/MediaTracker.java	7 Jun 2004 18:48:32 -0000	1.5.10.1
+++ java/awt/MediaTracker.java	10 Jun 2004 16:06:08 -0000
@@ -86,9 +86,12 @@
       else
         status = 0;
 
-      synchronized (MediaTracker.this)
+      if ((status & COMPLETE) == COMPLETE)
       {
-	MediaTracker.this.notifyAll();
+        synchronized (MediaTracker.this)
+        {
+          MediaTracker.this.notifyAll();
+        }
       }
       // If status is not COMPLETE then we need more updates.
       return (status & COMPLETE) == 0;

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