Removed cds::OS::is_thread_alive() function. This function is based of pthread_kill...
authorkhizmax <libcds.dev@gmail.com>
Tue, 7 Feb 2017 18:26:04 +0000 (21:26 +0300)
committerkhizmax <libcds.dev@gmail.com>
Tue, 7 Feb 2017 18:26:04 +0000 (21:26 +0300)
cds/os/posix/thread.h
cds/os/win/thread.h
cds/urcu/details/base.h
src/dhp.cpp
src/hp.cpp

index 64e6f26ff740dc58e96d1d3891e249ca4b09379c..399c93752dc04cc05ad19c60447ffd0ec68537de 100644 (file)
@@ -46,15 +46,6 @@ namespace cds { namespace OS {
         {
             return pthread_self();
         }
-
-        /// Checks if thread \p id is alive
-        static inline bool is_thread_alive( ThreadId id )
-        {
-            // if sig is zero, error checking is performed but no signal is actually sent.
-            // ESRCH - No thread could be found corresponding to that specified by the given thread ID
-            // Unresolved problem: Linux may crash on dead thread_id. Workaround unknown (except signal handler...)
-            return pthread_kill( id, 0 ) != ESRCH;
-        }
     }    // namespace posix
 
     //@cond
index 93f2440dc82cbf1949242bc716391ff577322f61..023f330696db9e69d0ceea8576314d465b5c4e63 100644 (file)
@@ -48,16 +48,6 @@ namespace cds { namespace OS {
         {
             return ::GetCurrentThreadId();
         }
-
-        /// Tests whether the thread is alive
-        static inline bool is_thread_alive( ThreadId id )
-        {
-            HANDLE h = ::OpenThread( SYNCHRONIZE, FALSE, id );
-            if ( h == nullptr )
-                return false;
-            ::CloseHandle( h );
-            return true;
-        }
     }    // namespace Win32
 
     //@cond
@@ -66,7 +56,6 @@ namespace cds { namespace OS {
 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
     using Win32::ThreadId;
     using Win32::get_current_thread_id;
-    using Win32::is_thread_alive;
 #endif
     //@endcond
 
index 638eb876b27a1002c21081c6f8e711f78e50b0c2..ea910e31deb50d495ca297a3649db63ec634d5e0 100644 (file)
@@ -424,7 +424,6 @@ namespace cds {
 
                         assert( p->m_list.m_idOwner.load( atomics::memory_order_relaxed ) == nullThreadId
                             || p->m_list.m_idOwner.load( atomics::memory_order_relaxed ) == mainThreadId
-                            || !cds::OS::is_thread_alive( p->m_list.m_idOwner.load( atomics::memory_order_relaxed ))
                             );
 
                         al.Delete( p );
index 462de952549eeb029938fd910ed63ced9e2b9c2b..0991de10da0b060166c1907462dc39da7f565064 100644 (file)
@@ -210,8 +210,7 @@ namespace cds { namespace gc { namespace dhp {
         for ( thread_record* hprec = pHead; hprec; hprec = pNext )
         {
             assert( hprec->m_idOwner.load( atomics::memory_order_relaxed ) == nullThreadId
-                || hprec->m_idOwner.load( atomics::memory_order_relaxed ) == mainThreadId
-                || !cds::OS::is_thread_alive( hprec->m_idOwner.load( atomics::memory_order_relaxed ) )
+                || hprec->m_idOwner.load( atomics::memory_order_relaxed ) == mainThreadId )
             );
 
             retired_array& retired = hprec->retired_;
@@ -459,6 +458,9 @@ namespace cds { namespace gc { namespace dhp {
         const cds::OS::ThreadId curThreadId = cds::OS::get_current_thread_id();
         for ( thread_record* hprec = thread_list_.load( atomics::memory_order_acquire ); hprec; hprec = hprec->m_pNextNode.load( atomics::memory_order_relaxed ) )
         {
+            if ( hprec == static_cast<thread_record*>( pThis ))
+                continue;
+
             // If m_bFree == true then hprec->retired_ is empty - we don't need to see it
             if ( hprec->m_bFree.load( atomics::memory_order_acquire ) ) {
                 assert( hprec->retired_.empty() );
@@ -469,7 +471,7 @@ namespace cds { namespace gc { namespace dhp {
             // Several threads may work concurrently so we use atomic technique
             {
                 cds::OS::ThreadId curOwner = hprec->m_idOwner.load( atomics::memory_order_relaxed );
-                if ( curOwner == nullThreadId || !cds::OS::is_thread_alive( curOwner ) ) {
+                if ( curOwner == nullThreadId ) {
                     if ( !hprec->m_idOwner.compare_exchange_strong( curOwner, curThreadId, atomics::memory_order_acquire, atomics::memory_order_relaxed ) )
                         continue;
                 }
@@ -478,7 +480,7 @@ namespace cds { namespace gc { namespace dhp {
             }
 
             // We own the thread record successfully. Now, we can see whether it has retired pointers.
-            // If it has ones then we move to pThis that is private for current thread.
+            // If it has ones then we move them to pThis that is private for current thread.
             retired_array& src = hprec->retired_;
             retired_array& dest = pThis->retired_;
 
index 6481a2cc5d8ad99e046386518eec3e1642885a6f..99a3d1659fc2298574c891d182832519d44f5dcb 100644 (file)
@@ -162,8 +162,7 @@ namespace cds { namespace gc { namespace hp {
         for ( thread_record* hprec = pHead; hprec; hprec = pNext )
         {
             assert( hprec->m_idOwner.load( atomics::memory_order_relaxed ) == nullThreadId
-                || hprec->m_idOwner.load( atomics::memory_order_relaxed ) == mainThreadId
-                || !cds::OS::is_thread_alive( hprec->m_idOwner.load( atomics::memory_order_relaxed ) )
+                || hprec->m_idOwner.load( atomics::memory_order_relaxed ) == mainThreadId )
             );
 
             retired_array& arr = hprec->retired_;
@@ -256,7 +255,6 @@ namespace cds { namespace gc { namespace hp {
     CDS_EXPORT_API void smr::free_thread_data( smr::thread_record* pRec )
     {
         assert( pRec != nullptr );
-        //CDS_HAZARDPTR_STATISTIC( ++m_Stat.m_RetireHPRec )
 
         pRec->hazards_.clear();
         scan( pRec );
@@ -447,6 +445,9 @@ namespace cds { namespace gc { namespace hp {
         const cds::OS::ThreadId curThreadId = cds::OS::get_current_thread_id();
         for ( thread_record* hprec = thread_list_.load( atomics::memory_order_acquire ); hprec; hprec = hprec->m_pNextNode.load( atomics::memory_order_relaxed ))
         {
+            if ( hprec == static_cast<thread_record*>( pThis ))
+                continue;
+
             // If m_bFree == true then hprec->retired_ is empty - we don't need to see it
             if ( hprec->m_bFree.load( atomics::memory_order_acquire ))
                 continue;
@@ -455,7 +456,7 @@ namespace cds { namespace gc { namespace hp {
             // Several threads may work concurrently so we use atomic technique only.
             {
                 cds::OS::ThreadId curOwner = hprec->m_idOwner.load( atomics::memory_order_relaxed );
-                if ( curOwner == nullThreadId || !cds::OS::is_thread_alive( curOwner ) ) {
+                if ( curOwner == nullThreadId ) {
                     if ( !hprec->m_idOwner.compare_exchange_strong( curOwner, curThreadId, atomics::memory_order_acquire, atomics::memory_order_relaxed ) )
                         continue;
                 }
@@ -464,7 +465,7 @@ namespace cds { namespace gc { namespace hp {
             }
 
             // We own the thread record successfully. Now, we can see whether it has retired pointers.
-            // If it has ones then we move to pThis that is private for current thread.
+            // If it has ones then we move them to pThis that is private for current thread.
             retired_array& src = hprec->retired_;
             retired_array& dest = pThis->retired_;
             assert( !dest.full() );