From 7ee38e6255cbe7789491e32ce48fb85b500934c9 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 27 May 2021 15:20:48 +0200 Subject: [PATCH] threads: disable thread attributes when compiled with TSAN TSAN doesn't work well then threads are created with attributes thar require root rights but the process is run as normal user. this patch avoid the thread attributes in this case. TSAN isn't going to be used for production builds. --- CMakeLists.txt | 2 +- lib/src/common/threads.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b9e86333..a5682e077 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -486,7 +486,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") endif (ENABLE_ASAN) if (ENABLE_TSAN) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -DHAVE_TSAN") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") endif (ENABLE_TSAN) diff --git a/lib/src/common/threads.c b/lib/src/common/threads.c index a53aebfa8..bad3d05d7 100644 --- a/lib/src/common/threads.c +++ b/lib/src/common/threads.c @@ -136,6 +136,11 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void* } } +// TSAN seems to have issues with thread attributes when running as normal user, disable them in that case +#if HAVE_TSAN + attr_enable = false; +#endif + int err = pthread_create(thread, attr_enable ? &attr : NULL, start_routine, arg); if (err) { if (EPERM == err) {