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

Win32: GC even resumes threads that had been suspended prior to GC

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      x86
    • OS:
      windows_95
    • Verification:
      Not verified

      Description

      [Tim, 7/15/96: Test case added to bottom of description]

      On win32 the function that puts all the threads to sleep but the one doing
      GC does this using suspend/resume. Resume *always* wakes a thread up -
      it doesn't keep track of how many times the thread has been suspended.
      Thus, when GC is over, a thread that was suspended coming in to GC will
      be resumed. We need to keep track of threads that were already suspended
      when going in to GC, and not wake them up.

      Offending code from src/win32/java/runtime/threads_md.c:

      /*
       * Continue execution of the specified thread.
       */
      int
      sysThreadResume(sys_thread_t *tid)
      {
          unsigned long n;

          /* Decrement thread's suspend count until no longer suspended */
          tid->state = RUNNABLE;
          while ((n = ResumeThread(tid->handle)) > 1) {
              if (n == 0xffffffffUL) {
                  return SYS_ERR;
              }
          }
          return SYS_OK;
      }

      /*
       * Helper function for sysThreadMulti()
       */
      static int
      threadMultiHelper(sys_thread_t *tid, void *self)
      {
          return tid == self ? SYS_OK : sysThreadResume(tid);
      }
       
      /*
       * Wakes up each thread in active thread queue except for the calling
       * thread. Returns SYS_ERR if not all threads could be woken up.
       */
      void
      sysThreadMulti(void)
      {
          sysThreadEnumerateOver(threadMultiHelper, sysThreadSelf());
      }


      Here is a test case: the thread should stay suspended for 10 seconds when it
      says it should. On Win32 prior to 1.1 the suspended thread was resumed
      immediately after GC:

      class SuspendTest extends Thread {
          public void run() {
      System.out.println("suspending self");
      suspend();
      System.out.println("hello");
          }
      }

      class suspendGCtest {
          public static void main(String args[]) {
      SuspendTest test1;

      test1 = new SuspendTest();
      test1.start();
      try { Thread.currentThread().sleep(1000); } catch (Exception e) {}
      System.out.println(
      "Calling GC: suspended thread should stay suspended 10 seconds");
      System.gc();
      try { Thread.currentThread().sleep(10000); } catch (Exception e) {}
      System.out.println("Resuming thread");
      test1.resume();
          }
      }

        Attachments

          Activity

            People

            Assignee:
            tlindholsunw Timothy Lindholm (Inactive)
            Reporter:
            tlindholsunw Timothy Lindholm (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: