src/os/windows/vm/os_windows.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6498151 Sdiff src/os/windows/vm

src/os/windows/vm/os_windows.cpp

Print this page
6498581: ThreadInterruptTest3 produces wrong output on Windows


3596   // resulting in multiple notifications.  We do, however, want the store
3597   // to interrupted() to be visible to other threads before we post
3598   // the interrupt event.
3599   OrderAccess::release();
3600   SetEvent(osthread->interrupt_event());
3601   // For JSR166:  unpark after setting status
3602   if (thread->is_Java_thread())
3603     ((JavaThread*)thread)->parker()->unpark();
3604 
3605   ParkEvent * ev = thread->_ParkEvent ;
3606   if (ev != NULL) ev->unpark() ;
3607 
3608 }
3609 
3610 
3611 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3612   assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(),
3613          "possibility of dangling Thread pointer");
3614 
3615   OSThread* osthread = thread->osthread();
3616   bool interrupted = osthread->interrupted();
3617   // There is no synchronization between the setting of the interrupt
3618   // and it being cleared here. It is critical - see 6535709 - that
3619   // we only clear the interrupt state, and reset the interrupt event,
3620   // if we are going to report that we were indeed interrupted - else
3621   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3622   // depending on the timing


3623   if (interrupted && clear_interrupted) {
3624     osthread->set_interrupted(false);
3625     ResetEvent(osthread->interrupt_event());
3626   } // Otherwise leave the interrupted state alone
3627 
3628   return interrupted;
3629 }
3630 
3631 // Get's a pc (hint) for a running thread. Currently used only for profiling.
3632 ExtendedPC os::get_thread_pc(Thread* thread) {
3633   CONTEXT context;
3634   context.ContextFlags = CONTEXT_CONTROL;
3635   HANDLE handle = thread->osthread()->thread_handle();
3636 #ifdef _M_IA64
3637   assert(0, "Fix get_thread_pc");
3638   return ExtendedPC(NULL);
3639 #else
3640   if (GetThreadContext(handle, &context)) {
3641 #ifdef _M_AMD64
3642     return ExtendedPC((address) context.Rip);




3596   // resulting in multiple notifications.  We do, however, want the store
3597   // to interrupted() to be visible to other threads before we post
3598   // the interrupt event.
3599   OrderAccess::release();
3600   SetEvent(osthread->interrupt_event());
3601   // For JSR166:  unpark after setting status
3602   if (thread->is_Java_thread())
3603     ((JavaThread*)thread)->parker()->unpark();
3604 
3605   ParkEvent * ev = thread->_ParkEvent ;
3606   if (ev != NULL) ev->unpark() ;
3607 
3608 }
3609 
3610 
3611 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3612   assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(),
3613          "possibility of dangling Thread pointer");
3614 
3615   OSThread* osthread = thread->osthread();

3616   // There is no synchronization between the setting of the interrupt
3617   // and it being cleared here. It is critical - see 6535709 - that
3618   // we only clear the interrupt state, and reset the interrupt event,
3619   // if we are going to report that we were indeed interrupted - else
3620   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3621   // depending on the timing. By checking thread interrupt event to see
3622   // if the thread gets real interrupt thus prevent spurious wakeup. 
3623   bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0);
3624   if (interrupted && clear_interrupted) {
3625     osthread->set_interrupted(false);
3626     ResetEvent(osthread->interrupt_event());
3627   } // Otherwise leave the interrupted state alone
3628 
3629   return interrupted;
3630 }
3631 
3632 // Get's a pc (hint) for a running thread. Currently used only for profiling.
3633 ExtendedPC os::get_thread_pc(Thread* thread) {
3634   CONTEXT context;
3635   context.ContextFlags = CONTEXT_CONTROL;
3636   HANDLE handle = thread->osthread()->thread_handle();
3637 #ifdef _M_IA64
3638   assert(0, "Fix get_thread_pc");
3639   return ExtendedPC(NULL);
3640 #else
3641   if (GetThreadContext(handle, &context)) {
3642 #ifdef _M_AMD64
3643     return ExtendedPC((address) context.Rip);


src/os/windows/vm/os_windows.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File