diff --git a/CMakeLists.txt b/CMakeLists.txt index c73fe127acce07665d480f089fedbe08b9d3833a..51226aac4d37fae8082c5ac40f25282c350008c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,10 +181,10 @@ add_custom_target(fullunittests tests/cta-unitTests COMMAND tests/cta-unitTests-multiProcess COMMAND valgrind --track-fds=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1 --suppressions=tests/valgrind.suppr tests/cta-unitTests - COMMAND valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests + COMMAND valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr --sim-hints=no-nptl-pthread-stackcache tests/cta-unitTests COMMAND tests/cta-unitTests-multiProcess COMMAND valgrind --track-fds=yes --child-silent-after-fork=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1 --suppressions=tests/valgrind.suppr tests/cta-unitTests-multiProcess - COMMAND valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests-multiProcess + COMMAND valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr --sim-hints=no-nptl-pthread-stackcache tests/cta-unitTests-multiProcess DEPENDS tests/cta-unitTests tests/cta-unitTests-multiProcess tests/valgrind.suppr tests/helgrind.suppr COMMENT "Running unit tests with memory leak and race conditions detection" VERBATIM) @@ -197,8 +197,8 @@ add_custom_target(valgrind COMMENT "Running unit tests with memory leak detection" VERBATIM) add_custom_target(helgrind - valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests - COMMAND valgrind --tool=helgrind -v --child-silent-after-fork=yes --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests-multiProcess + valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests --sim-hints=no-nptl-pthread-stackcache + COMMAND valgrind --tool=helgrind -v --child-silent-after-fork=yes --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr --sim-hints=no-nptl-pthread-stackcache tests/cta-unitTests-multiProcess DEPENDS tests/cta-unitTests tests/cta-unitTests-multiProcess tests/helgrind.suppr COMMENT "Running unit tests with race conditions detection" VERBATIM) diff --git a/objectstore/BackendVFS.cpp b/objectstore/BackendVFS.cpp index 108d6ea4ccea6dd9cfe0143af55f396b81cdb40c..2f3daad10c122c84851829f0f2e43633f9406177 100644 --- a/objectstore/BackendVFS.cpp +++ b/objectstore/BackendVFS.cpp @@ -23,6 +23,7 @@ #include "common/Timer.hpp" #include "tests/TestsCompileTimeSwitches.hpp" #include "common/exception/Exception.hpp" +#include "common/threading/MutexLocker.hpp" #include <fstream> #include <stdlib.h> @@ -441,24 +442,29 @@ void BackendVFS::AsyncDeleter::wait() { } BackendVFS::AsyncLockfreeFetcher::AsyncLockfreeFetcher(BackendVFS& be, const std::string& name): - m_backend(be), m_name(name), - m_job(std::async(std::launch::async, - [&](){ - auto ret = m_backend.read(name); - ANNOTATE_HAPPENS_BEFORE(&m_job); - return ret; - })) -{ } + m_backend(be), m_name(name) { + cta::threading::Thread::start(); +} + +void BackendVFS::AsyncLockfreeFetcher::run() { + threading::MutexLocker ml(m_mutex); + try { + m_value = m_backend.read(m_name); + } catch (...) { + m_exception = std::current_exception(); + } +} Backend::AsyncLockfreeFetcher* BackendVFS::asyncLockfreeFetch(const std::string& name) { return new AsyncLockfreeFetcher(*this, name); } std::string BackendVFS::AsyncLockfreeFetcher::wait() { - auto ret = m_job.get(); - ANNOTATE_HAPPENS_AFTER(&m_job); - ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&m_job); - return ret; + cta::threading::Thread::wait(); + threading::MutexLocker ml(m_mutex); + if (m_exception) + std::rethrow_exception(m_exception); + return m_value; } std::string BackendVFS::Parameters::toStr() { diff --git a/objectstore/BackendVFS.hpp b/objectstore/BackendVFS.hpp index 39952d955344501300a8666244ca4b41576db256..6bd2cd03c7d1ee78a5625428fe7121d83bd2e86b 100644 --- a/objectstore/BackendVFS.hpp +++ b/objectstore/BackendVFS.hpp @@ -19,6 +19,7 @@ #pragma once #include "Backend.hpp" +#include "common/threading/Thread.hpp" #include <future> #include <functional> @@ -127,7 +128,7 @@ public: /** * A class mimicking AIO using C++ async tasks */ - class AsyncLockfreeFetcher: public Backend::AsyncLockfreeFetcher { + class AsyncLockfreeFetcher: public Backend::AsyncLockfreeFetcher, public cta::threading::Thread { public: AsyncLockfreeFetcher(BackendVFS & be, const std::string & name); std::string wait() override; @@ -136,8 +137,14 @@ public: BackendVFS &m_backend; /** The object name */ const std::string m_name; - /** The future that will both do the job and allow synchronization with the caller. */ - std::future<std::string> m_job; + /** The fetched value */ + std::string m_value; + /** The exception we might receive */ + std::exception_ptr m_exception = nullptr; + /** A mutex to make helgrind happy */ + cta::threading::Mutex m_mutex; + /** The thread that will both do the job and allow synchronization with the caller. */ + void run() override; }; Backend::AsyncUpdater* asyncUpdate(const std::string & name, std::function <std::string(const std::string &)> & update) override; diff --git a/tests/helgrind.suppr b/tests/helgrind.suppr index 4644eb969cb193d0418855d44385ff60914dfdf2..45d6d9bf4a559cbb034789e0775aafb540348dbc 100644 --- a/tests/helgrind.suppr +++ b/tests/helgrind.suppr @@ -580,4 +580,17 @@ fun:_ZNSt10shared_ptrINSt6thread10_Impl_baseEED1Ev fun:_ZNSt6thread10_Impl_baseD1Ev ... +} + +{ + pthread_create_stack_creation + Helgrind:Race + fun:memset + fun:get_cached_stack + fun:allocate_stack + fun:pthread_create@@GLIBC_2.2.5 + fun:pthread_create_WRK + fun:pthread_create@* + fun:__gthread_create + ... } \ No newline at end of file