Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5031999

(thread) Waiting thread is unexpectedly awakened.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      Name: rmT116609 Date: 04/14/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_03"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
      Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

      FULL OS VERSION :
      Windows 2000 Professional
      Version 5.00.2195
      Service Pack 4


      A DESCRIPTION OF THE PROBLEM :
      When a number of threads call wait(0) on an instance of another Thread, the waiting threads are unexpectedly awakened when the other thread finishes run() and dies. Identical behvior was noted on Linux kernel 2.4.22 and similar behavior on Windows XP Professional where 35% of the time similar results were noted, 5% with some threads deadlocking and some not and 60% with all threads deadlocking.

      This would seem to be in violation of JVM Spec 8.14 and JLS Spec 17.14 as neither notify() nor notifyAll() are called in the example given.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the code example.
      (java ThreadSyncTest)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the anonymous ThreadSyncTest objects to deadlock since nowhere in the code is notify() or notifyAll() called on the DeadThread instance.
      ACTUAL -
      All waiting threads are awakened and print "Got lock:..." when the DeadThread instance completes run() and its thread dies. It seems apparent that upon the thread exiting run() that notifyAll() is somehow called in native code. The current implementaion of Thread.join() implies the same thing so this may be a JDK issue instead of a VM issue.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      public class ThreadSyncTest extends Thread
      {
          DeadThread dt;

          public ThreadSyncTest(DeadThread dt)
          {
              this.dt = dt;
          }

          public void run()
          {
              System.out.println("ThreadSyncTest.run" + " " + Thread.currentThread().getName());
              synchronized (dt)
              {
                  try
                  {
                      System.out.println("Waiting for dead thread...");
                      dt.wait();
                      System.out.println("Got lock: ThreadSyncTest " + Thread.currentThread().getName());
                  }
                  catch (InterruptedException e) {}
              }
          }

          public static void main(String[] args)
          {
              DeadThread dt = new DeadThread();
              new ThreadSyncTest(dt).start();
              new ThreadSyncTest(dt).start();
              new ThreadSyncTest(dt).start();
              dt.start();
          }
      }

      class DeadThread extends Thread
      {
          public void run()
          {
              System.out.println("DeadThread ending.");
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      This bug report is being filed more for aesthetic than practical reasons as no good developer would use code as in the example, but it seems obvious that running Thread objects should not be used as object locks as locking threads can unexpectedly (and perhaps in violation of the specs) be awakened which might interfere with the rest of the locking logic employed by the developer.
      (Incident Review ID: 243341)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            psoper Pete Soper (Inactive)
            Reporter:
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: