Skip to content

bthread: use BAIDU_GET_VOLATILE_THREAD_LOCAL to access tls_unique_use…#3393

Merged
yanglimingcn merged 1 commit into
apache:masterfrom
altman08:dev
Jul 17, 2026
Merged

bthread: use BAIDU_GET_VOLATILE_THREAD_LOCAL to access tls_unique_use…#3393
yanglimingcn merged 1 commit into
apache:masterfrom
altman08:dev

Conversation

@altman08

Copy link
Copy Markdown
Contributor

…r_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.

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

…r_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.
@yanglimingcn

Copy link
Copy Markdown
Contributor

LGTM

@yanglimingcn
yanglimingcn merged commit e5ff754 into apache:master Jul 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants