Page 1 of 1
Thread Local Storage
Posted: Mon Nov 17, 2014 5:33 pm
by sortie
Hi,
I wrote a wiki article on
Thread Local Storage on System V ABI platforms using the __thread keyword. It contains information on how the ABI works, links to more information, and advise on how to implement this yourself. I also put up
notes on how I do this in my operating system as a more concrete example.
It's a bit of a rough draft, do let me know if you find this interesting or have suggestions for improvement.
It needs to be linked to from some other pages, not sure which ones are related.
Share and Enjoy!
Re: Thread Local Storage
Posted: Tue Nov 18, 2014 1:23 pm
by eryjus
Sortie,
sortie wrote:[...] or have suggestions for improvement.
Great article. I'm sure I will be referencing it in the future.
My comments are more about readability than content. These are just a couple of things that jump off a page at me and since this is a new article, I thought I would offer my opinion.
You use the acronym "TLS"
here without explicitly defining its meaning at the top of the wiki. It actually took me a moment to figure out what TLS stood for.
Also, you use "TLS" in upper case as well as "tls" in lower case in the same section. I would suggest being consistent.
Re: Thread Local Storage
Posted: Tue Nov 18, 2014 2:30 pm
by sortie
Thanks. :)
It's now fixed: I defined TLS in the first sentence and made the rest of the article more consistent by spelling it out most of the time.
Re: Thread Local Storage
Posted: Wed Nov 19, 2014 2:22 am
by max
sortie wrote:Thanks.
It's now fixed: I defined TLS in the first sentence and made the rest of the article more consistent by spelling it out most of the time.
Thanks for writing that article sortie!
I'll implement TLS in my kernel once I'm healthy again.
P.S.: on this occasion I'll also check if you're stuff is austypogehaftet to see if it's all fine.
<3
Re: Thread Local Storage
Posted: Sat Nov 22, 2014 12:00 am
by Arto
Sortie,
Thanks for writing all that. Tremendously helpful not just for OS dev, but also for standard C library implementation.
Re: Thread Local Storage
Posted: Fri Mar 06, 2015 4:04 pm
by max
Finally implemented TLS in Ghost today. Thanks a lot again sortie.
I have a question though, you use this calculation for the alignment:
Code: Select all
max(master_tls_alignment, alignof(struct uthread));
This confused me a little trying to figure out how to align the address of the location that contains the self-pointer (and therefore the location of the user-thread-struct) properly. What if the alignment of the TLS was 4, but the alignment of the user-thread struct was 8 - wouldn't the location that contains the self-pointer of the user-thread struct be set off by 4 bytes too much?
Also, I made this little visualization, is it correct & maybe helpful for the wiki?