PoC: Replace Thread::Local(T)
with Thread::LocalStorage
(alternative)
#16168
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.
This is an alternative to #16029 that uses a static "container type" instead of a table of void pointers. It roughly moves hard coded values from
Thread.current
into a dedicated type (allocated when needed) and relies on a macro to generate some code.It has some advantages, most notably a much simpler implementation and the ability to store any type (not just pointers and nilable references).
It also has some disadvantages, for example it depends on the macro and we lose flexility (must use the generated class method, can only create globals, no runtime dynamism), any declared thread local will grow the container type regardless of actual usage, which in turn requires to set the destructor callback to when we set the TLS... though now that I think about it, I should just use a wrapper class with a finalizer instead 🤦
Credits where its due: the initial idea is from @BlobCodes. See #15616 (comment) and #15889.