From 5ae42cafc405c88f9d3b15b6145b964a8ef093ab Mon Sep 17 00:00:00 2001 From: Lukas W Date: Mon, 11 May 2020 17:11:11 +0200 Subject: [PATCH] Try to fix libcds counters issues * For unknown reasons, _cdslib::_thread_counter is never initialized, trigger initialization manually by referencing during MemoryPool's construction. * CircleCI linux.gcc test crashes on exit with an "invalid delete" at hpGC.reset() in libcds.cpp. I don't know what causes this, but it turns out we don't need garbage collection currently (we only use VyukovMPMCCycleQueue), so we can just remove the garbage collection for now. --- include/libcds.h | 4 +++- src/core/MemoryPool.cpp | 2 ++ src/core/libcds.cpp | 13 ++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/libcds.h b/include/libcds.h index 7d4af9084..ac051ca00 100644 --- a/include/libcds.h +++ b/include/libcds.h @@ -17,5 +17,7 @@ namespace _cdslib void thread_deinit(); static NiftyCounter _counter; - static NiftyCounterTL _thread_counter; + static thread_local NiftyCounterTL<_cdslib::thread_init, _cdslib::thread_deinit> _thread_counter; } + +#define CDS_THREAD_GUARD() (void)_cdslib::_thread_counter; diff --git a/src/core/MemoryPool.cpp b/src/core/MemoryPool.cpp index 62dfad078..fce0c14df 100644 --- a/src/core/MemoryPool.cpp +++ b/src/core/MemoryPool.cpp @@ -28,6 +28,8 @@ public: , m_numElms(nmemb) , m_freelist(nmemb) { + CDS_THREAD_GUARD(); + m_buffer = new char[m_elementSize * m_numElms]; for (size_t i = 0; i < m_numElms; i++) { m_freelist.push(m_buffer + (i * m_elementSize)); diff --git a/src/core/libcds.cpp b/src/core/libcds.cpp index ef7ac3a88..eb97a1616 100644 --- a/src/core/libcds.cpp +++ b/src/core/libcds.cpp @@ -1,7 +1,6 @@ #include "libcds.h" #include -#include #include #include "stdshims.h" @@ -9,28 +8,28 @@ namespace _cdslib { -static std::unique_ptr hpGC; - void init() { cds::Initialize(); - hpGC = make_unique(); } void deinit() { - hpGC.reset(); cds::Terminate(); } void thread_init() { - cds::threading::Manager::attachThread(); + if (! cds::threading::Manager::isThreadAttached()) { + cds::threading::Manager::attachThread(); + } } void thread_deinit() { - cds::threading::Manager::detachThread(); + if (cds::threading::Manager::isThreadAttached()) { + cds::threading::Manager::detachThread(); + } } }