From ef64bc1e0ac036a94b1ea358e4ea55c447ed684a Mon Sep 17 00:00:00 2001 From: altman08 <936396749@qq.com> Date: Fri, 17 Jul 2026 18:45:26 +0800 Subject: [PATCH] bthread: use BAIDU_GET_VOLATILE_THREAD_LOCAL to access tls_unique_user_ptr in sched_to tls_unique_user_ptr was read directly without going through the BAIDU_GET_VOLATILE_THREAD_LOCAL macro in TaskGroup::sched_to, while the paired write later in the same function correctly used BAIDU_SET_VOLATILE_THREAD_LOCAL. sched_to contains jump_stack, a suspend-point where GCC (aarch64) and Clang may incorrectly cache the address of a thread_local variable, which is exactly the hazard BAIDU_GET_VOLATILE_THREAD_LOCAL is designed to avoid. Fix the read to use the macro for consistency and correctness. --- src/bthread/task_group.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bthread/task_group.cpp b/src/bthread/task_group.cpp index e54f947542..72a6b91836 100644 --- a/src/bthread/task_group.cpp +++ b/src/bthread/task_group.cpp @@ -817,7 +817,7 @@ void TaskGroup::sched_to(TaskGroup** pg, TaskMeta* next_meta) { #endif // Save errno so that errno is bthread-specific. int saved_errno = errno; - void* saved_unique_user_ptr = tls_unique_user_ptr; + void* saved_unique_user_ptr = BAIDU_GET_VOLATILE_THREAD_LOCAL(tls_unique_user_ptr); TaskMeta* const cur_meta = g->_cur_meta; int64_t now = butil::cpuwide_time_ns();