diff --git a/configure.ac b/configure.ac index 4de43ecdf0..e944158815 100644 --- a/configure.ac +++ b/configure.ac @@ -865,8 +865,23 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ } ])], [ - AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.]) - AC_MSG_RESULT(yes) + case $host in + *mingw*) + # mingw32's implementation of thread_local has also been shown to behave + # erroneously under concurrent usage; see: + # https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605 + AC_MSG_RESULT(no) + ;; + *darwin*) + # TODO enable thread_local on later versions of Darwin where it is + # supported (per https://stackoverflow.com/a/29929949) + AC_MSG_RESULT(no) + ;; + *) + AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.]) + AC_MSG_RESULT(yes) + ;; + esac ], [ AC_MSG_RESULT(no) diff --git a/src/Makefile.am b/src/Makefile.am index f2f6ddc879..de035cd559 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -265,6 +265,7 @@ BITCOIN_CORE_H = \ utilmoneystr.h \ utilstring.h \ utiltime.h \ + utilthreadnames.h \ validation.h \ validationinterface.h \ versionbits.h \ @@ -591,6 +592,7 @@ libdash_util_a_SOURCES = \ utilstrencodings.cpp \ utiltime.cpp \ utilstring.cpp \ + utilthreadnames.cpp \ $(BITCOIN_CORE_H) if GLIBC_BACK_COMPAT diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 4d3c6f4d6f..b789dbb157 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -102,6 +102,7 @@ BITCOIN_TESTS =\ test/streams_tests.cpp \ test/subsidy_tests.cpp \ test/sync_tests.cpp \ + test/util_threadnames_tests.cpp \ test/timedata_tests.cpp \ test/torcontrol_tests.cpp \ test/transaction_tests.cpp \ diff --git a/src/dashd.cpp b/src/dashd.cpp index 2dae5598f6..1d5277470d 100644 --- a/src/dashd.cpp +++ b/src/dashd.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,8 @@ static bool AppInit(int argc, char* argv[]) { bool fRet = false; + util::ThreadRename("init"); + // // Parameters // diff --git a/src/httpserver.cpp b/src/httpserver.cpp index b7bd24333b..6305193428 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include // For HTTP status codes #include @@ -18,7 +19,7 @@ #include #include #include -#include +#include #include #include @@ -286,7 +287,7 @@ static void http_reject_request_cb(struct evhttp_request* req, void*) /** Event dispatcher thread */ static bool ThreadHTTP(struct event_base* base, struct evhttp* http) { - RenameThread("dash-http"); + util::ThreadRename("http"); LogPrint(BCLog::HTTP, "Entering http event loop\n"); event_base_dispatch(base); // Event loop will be interrupted by InterruptHTTPServer() @@ -337,9 +338,9 @@ static bool HTTPBindAddresses(struct evhttp* http) } /** Simple wrapper to set thread name and run work queue */ -static void HTTPWorkQueueRun(WorkQueue* queue) +static void HTTPWorkQueueRun(WorkQueue* queue, int worker_num) { - RenameThread("dash-httpworker"); + util::ThreadRename(strprintf("httpworker.%i", worker_num)); queue->Run(); } @@ -440,7 +441,7 @@ bool StartHTTPServer() threadHTTP = std::thread(ThreadHTTP, eventBase, eventHTTP); for (int i = 0; i < rpcThreads; i++) { - g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue); + g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue, i); } return true; } diff --git a/src/init.cpp b/src/init.cpp index 71d290f488..960077f5be 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -39,6 +39,7 @@ #include