-
Notifications
You must be signed in to change notification settings - Fork 471
Use _Thread_local for thread-local storage #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cc @compnerd |
src/init.c
Outdated
#if defined(_WIN32) | ||
__declspec(thread) struct dispatch_tsd __dispatch_tsd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would using _Thread_local
work instead? I would assume it maps to the right thing on both platforms, and libdispatch otherwise already requires C11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSVC actually doesn't support C11 threads, so using __declspec(thread)
is the canonical method of declaring thread-local variables in Windows code. I agree that using _Thread_local
everywhere would be best if we don't care about building with MSVC (I don't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by MSVC you mean the MSFT C compiler as opposed to clang, correct? Not MSFT Visual Studio?
libdispatch needs clang (which is I'm told supported on Windows nowadays?) for blocks support anyway (and more). So yeah I don't think we care about MSVC in this instance, if _Thread_local
does the job, we should use it, __thread
really is a gcc-ism and C11 has the right thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by MSVC you mean the MSFT C compiler as opposed to clang, correct?
Right.
I updated this to use _Thread_local
now. Thanks for the guidance.
init.c currently does not compile for Windows with newer versions of Clang because it declares `__dispatch_tsd` with `__thread` but shims/tsd.h declares it with `__declspec(thread)`. Use the standard `_Thread_local` instead.
I think that using |
@swift-ci please test |
1 similar comment
@swift-ci please test |
Use _Thread_local for thread-local storage Signed-off-by: Kim Topley <[email protected]>
When building for Windows, shims/tsd.h declares __dispatch_tsd with
__declspec(thread). init.c needs to match this or else it will not compile with
newer versions of Clang.