Replace pthread specifics with C11 thread-local variables #811
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
C11 thread-local variables are faster and safer than pthread_specifics. Let's use them!
Unfortunately, the pretty alias
thread_local
is defined inthreads.h
, an optional part of C11 that Clang doesn't support yet. But the actual_Thread_local
storage classifier works just fine. It calls intotlv_get_addr
provided bydyld
, and it's a lot faster thanpthread_getspecific
.Docs: http://en.cppreference.com/w/c/language/storage_duration
Here's the latest source available:
https://opensource.apple.com/source/dyld/dyld-519.2.2/src/threadLocalHelpers.s.auto.html
So 32-bit ARM this is built on pthread_getspecific. 64-bit ARM uses some crazy assembly that I don't understand.