From 96012ef81ffe033dfc2ebf089910a0862c2c780c Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 11 May 2016 22:18:02 -0400 Subject: [PATCH] new attempt to fix thread issues --- libretroshare/src/util/rsthreads.cc | 8 +++++++- libretroshare/src/util/rsthreads.h | 9 ++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/util/rsthreads.cc b/libretroshare/src/util/rsthreads.cc index 96658b6dc..bab557a6a 100644 --- a/libretroshare/src/util/rsthreads.cc +++ b/libretroshare/src/util/rsthreads.cc @@ -127,7 +127,13 @@ void RsTickingThread::fullstop() #ifdef DEBUG_THREADS THREAD_DEBUG << " waiting stop" << std::endl; #endif - mHasStoppedSemaphore.wait(); + if(pthread_equal(mTid,pthread_self())) + { + std::cerr << "(WW) RsTickingThread::fullstop() called by same thread. This is unexpected." << std::endl; + return ; + } + + mHasStoppedSemaphore.wait_no_relock(); #ifdef DEBUG_THREADS THREAD_DEBUG << " finished!" << std::endl; #endif diff --git a/libretroshare/src/util/rsthreads.h b/libretroshare/src/util/rsthreads.h index cbbd2557e..ac08a9404 100644 --- a/libretroshare/src/util/rsthreads.h +++ b/libretroshare/src/util/rsthreads.h @@ -211,7 +211,9 @@ public: return s->val ; } - void wait() + // waits but does not re-locks the semaphore + + void wait_no_relock() { static const uint32_t max_waiting_time_before_warning=1000 *5 ; // 5 secs uint32_t tries=0; @@ -224,10 +226,7 @@ public: RS_STACK_MUTEX(s->mtx) ; if(s->val > 0) - { - --(s->val) ; - return ; - } + return ; } }