< prev index next >

src/hotspot/os/posix/os_posix.cpp

Print this page

        

*** 643,668 **** //////////////////////////////////////////////////////////////////////////////// // interrupt support void os::interrupt(Thread* thread) { debug_only(Thread::check_for_dangling_thread_pointer(thread);) ! OSThread* osthread = thread->osthread(); if (!osthread->interrupted()) { osthread->set_interrupted(true); // More than one thread can get here with the same value of osthread, // resulting in multiple notifications. We do, however, want the store // to interrupted() to be visible to other threads before we execute unpark(). OrderAccess::fence(); ! ParkEvent * const slp = thread->_SleepEvent ; if (slp != NULL) slp->unpark() ; } // For JSR166. Unpark even if interrupt status already was set ! if (thread->is_Java_thread()) ! ((JavaThread*)thread)->parker()->unpark(); ParkEvent * ev = thread->_ParkEvent ; if (ev != NULL) ev->unpark() ; } --- 643,668 ---- //////////////////////////////////////////////////////////////////////////////// // interrupt support void os::interrupt(Thread* thread) { debug_only(Thread::check_for_dangling_thread_pointer(thread);) ! assert(thread->is_Java_thread(), "invariant"); ! JavaThread* jt = (JavaThread*) thread; OSThread* osthread = thread->osthread(); if (!osthread->interrupted()) { osthread->set_interrupted(true); // More than one thread can get here with the same value of osthread, // resulting in multiple notifications. We do, however, want the store // to interrupted() to be visible to other threads before we execute unpark(). OrderAccess::fence(); ! ParkEvent * const slp = jt->_SleepEvent ; if (slp != NULL) slp->unpark() ; } // For JSR166. Unpark even if interrupt status already was set ! jt->parker()->unpark(); ParkEvent * ev = thread->_ParkEvent ; if (ev != NULL) ev->unpark() ; }
*** 680,690 **** // intentional. The effect of this is that Object.wait() and // LockSupport.park() will appear to have a spurious wakeup, which // is allowed and not harmful, and the possibility is so rare that // it is not worth the added complexity to add yet another lock. // For the sleep event an explicit reset is performed on entry ! // to os::sleep, so there is no early return. It has also been // recommended not to put the interrupted flag into the "event" // structure because it hides the issue. if (interrupted && clear_interrupted) { osthread->set_interrupted(false); // consider thread->_SleepEvent->reset() ... optional optimization --- 680,690 ---- // intentional. The effect of this is that Object.wait() and // LockSupport.park() will appear to have a spurious wakeup, which // is allowed and not harmful, and the possibility is so rare that // it is not worth the added complexity to add yet another lock. // For the sleep event an explicit reset is performed on entry ! // to JavaThread::sleep, so there is no early return. It has also been // recommended not to put the interrupted flag into the "event" // structure because it hides the issue. if (interrupted && clear_interrupted) { osthread->set_interrupted(false); // consider thread->_SleepEvent->reset() ... optional optimization
*** 2047,2057 **** // thread to block. This has the benefit of forcing a spurious return // from the first park() call after an unpark() call which will help // shake out uses of park() and unpark() without checking state conditions // properly. This spurious return doesn't manifest itself in any user code // but only in the correctly written condition checking loops of ObjectMonitor, ! // Mutex/Monitor, Thread::muxAcquire and os::sleep if (Atomic::xchg(1, &_event) >= 0) return; int status = pthread_mutex_lock(_mutex); assert_status(status == 0, status, "mutex_lock"); --- 2047,2057 ---- // thread to block. This has the benefit of forcing a spurious return // from the first park() call after an unpark() call which will help // shake out uses of park() and unpark() without checking state conditions // properly. This spurious return doesn't manifest itself in any user code // but only in the correctly written condition checking loops of ObjectMonitor, ! // Mutex/Monitor, Thread::muxAcquire and JavaThread::sleep if (Atomic::xchg(1, &_event) >= 0) return; int status = pthread_mutex_lock(_mutex); assert_status(status == 0, status, "mutex_lock");
< prev index next >