src: remove non-standard thread extensions
What changed, and why it matters
This commit replaces older, compiler-specific thread-local storage keywords (__thread) with standard C/C++ ones (thread_local and _Thread_local). It is a portability and standards-compliance cleanup. There is no direct evidence in the commit that this fixes an exploitable security vulnerability.
Treat as a routine maintenance/portability patch. No urgent security action is indicated by the diff alone. Standard review and testing for build compatibility on supported compilers is sufficient.
Security signals we found
Thread-local storage keyword modernization
No change to allocation, initialization, or access logic
No bounds checking, locking, or lifetime changes
No vendor security advisory or CVE referenced in commit
Evidence from the diff
The patch changes __thread to thread_local in C++ files and to _Thread_local in C files (except MSVC, which keeps __declspec(thread)). These are semantically equivalent for the thread-local storage use cases shown (performance timer pointer, threadpool depth/leaf flags, RandomX VM pointer, CryptoNight scratchpad). The change improves standards compliance and may avoid compiler-specific behavior, but the diff itself does not demonstrate a memory-safety bug, race condition, or information disclosure.
Changed components
src/common/perf_timer.cppsrc/common/threadpool.cppsrc/crypto/rx-slow-hash.csrc/crypto/slow-hash.cInspect captured patch +6 / −6
diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp
index a7acf11..fae0d74 100644
--- a/src/common/perf_timer.cpp
+++ b/src/common/perf_timer.cpp
@@ -92,9 +92,9 @@ el::Level performance_timer_log_level = el::Level::Info;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
#warning "Building with fuzzing mode UNSAFE FOR PRODUCTION!"
- __thread std::vector<LoggingPerformanceTimer*> *performance_timers = NULL;
+ thread_local std::vector<LoggingPerformanceTimer*> *performance_timers = NULL;
#else
- static __thread std::vector<LoggingPerformanceTimer*> *performance_timers = NULL;
+ static thread_local std::vector<LoggingPerformanceTimer*> *performance_timers = NULL;
#endif
void set_performance_timer_log_level(el::Level level)
diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp
index faa45e8..14ca5f4 100644
--- a/src/common/threadpool.cpp
+++ b/src/common/threadpool.cpp
@@ -31,8 +31,8 @@
#include "cryptonote_config.h"
#include "common/util.h"
-static __thread int depth = 0;
-static __thread bool is_leaf = false;
+static thread_local int depth = 0;
+static thread_local bool is_leaf = false;
namespace tools
{
diff --git a/src/crypto/rx-slow-hash.c b/src/crypto/rx-slow-hash.c
index 1dc3eb2..f04ae55 100644
--- a/src/crypto/rx-slow-hash.c
+++ b/src/crypto/rx-slow-hash.c
@@ -63,7 +63,7 @@ static int secondary_seedhash_set = 0;
#if defined(_MSC_VER)
#define THREADV __declspec(thread)
#else
-#define THREADV __thread
+#define THREADV _Thread_local
#endif
static THREADV randomx_vm *main_vm_full = NULL;
diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c
index 47ae2da..863c480 100644
--- a/src/crypto/slow-hash.c
+++ b/src/crypto/slow-hash.c
@@ -54,7 +54,7 @@
#if defined(_MSC_VER)
#define THREADV __declspec(thread)
#else
-#define THREADV __thread
+#define THREADV _Thread_local
#endif
extern void aesb_single_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
Why this scored 17/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.