TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

All about thread-local storage

50 pointsby MaskRayover 4 years ago

3 comments

theamkover 4 years ago
Interesting!<p>I had known that thread-local variables can be access pretty fast, via dedicated segment register, but I was not clear how can one make this work for dynamically loaded PIC code, like most .so files.<p>Turns out you can&#x27;t. You only get fast access via dedicated register if you are using variable declared in the main program. The .so files have to call special function which does multiple memory lookups to get the actual location, probably severely reducing performance.<p>(and this is another case when seemingly simple operation -- getting variable value -- gets internally translated to dozens of operations and a function call)
评论 #26154140 未加载
评论 #26151733 未加载
zmodemover 4 years ago
<a href="https:&#x2F;&#x2F;www.akkadia.org&#x2F;drepper&#x2F;tls.pdf" rel="nofollow">https:&#x2F;&#x2F;www.akkadia.org&#x2F;drepper&#x2F;tls.pdf</a> is also a great write-up
jstrongover 4 years ago
I have done plenty with threads but never used thread-local storage except when forced to by some other library using it. To me it seems like a bolted-on monstrosity that provides thread safety to thread-naive code after the fact. Am I missing something? Is this a good solution to some problem I haven&#x27;t encountered? Are there situations where the performance of TLS is better than some other solution?
评论 #26156129 未加载
评论 #26155266 未加载