diff src/os/windows/vm/os_windows.cpp @ 2386:083f13976b51

6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3 Summary: only clear the interrupt state if we will report that it was set Reviewed-by: dcubed, alanb, phh, coleenp, dice
author dholmes
date Mon, 21 Mar 2011 22:16:19 -0400
parents 5584e20db481
children 8b0236cbed14 5504afd15955 5def270bc147
line wrap: on
line diff
--- a/src/os/windows/vm/os_windows.cpp	Fri Mar 18 13:28:33 2011 -0700
+++ b/src/os/windows/vm/os_windows.cpp	Mon Mar 21 22:16:19 2011 -0400
@@ -3297,9 +3297,14 @@
          "possibility of dangling Thread pointer");
 
   OSThread* osthread = thread->osthread();
-  bool interrupted;
-  interrupted = osthread->interrupted();
-  if (clear_interrupted == true) {
+  bool interrupted = osthread->interrupted();
+  // There is no synchronization between the setting of the interrupt
+  // and it being cleared here. It is critical - see 6535709 - that
+  // we only clear the interrupt state, and reset the interrupt event,
+  // if we are going to report that we were indeed interrupted - else
+  // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
+  // depending on the timing
+  if (interrupted && clear_interrupted) {
     osthread->set_interrupted(false);
     ResetEvent(osthread->interrupt_event());
   } // Otherwise leave the interrupted state alone