diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -576,6 +576,7 @@ if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout) { // Timeout: Check transactions for update + // without holding ::mempool.cs to avoid deadlocks if (g_mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP) { break; diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -468,7 +469,7 @@ //! Value n means that n times in 2^32 we check. uint32_t nCheckFrequency GUARDED_BY(cs); //! Used by getblocktemplate to trigger CreateNewBlock() invocation - unsigned int nTransactionsUpdated; + std::atomic nTransactionsUpdated; //! sum of all mempool tx's sizes. uint64_t totalTxSize; diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -405,12 +405,10 @@ } unsigned int CTxMemPool::GetTransactionsUpdated() const { - LOCK(cs); return nTransactionsUpdated; } void CTxMemPool::AddTransactionsUpdated(unsigned int n) { - LOCK(cs); nTransactionsUpdated += n; }