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!
Thread Local Storage
- eryjus
- Member
- Posts: 286
- Joined: Fri Oct 21, 2011 9:47 pm
- Libera.chat IRC: eryjus
- Location: Tustin, CA USA
Re: Thread Local Storage
Sortie,
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.
Great article. I'm sure I will be referencing it in the future.sortie wrote:[...] or have suggestions for improvement.
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.
Adam
The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal
"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal
"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
Re: Thread Local Storage
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.
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.
- max
- Member
- Posts: 616
- Joined: Mon Mar 05, 2012 11:23 am
- Libera.chat IRC: maxdev
- Location: Germany
- Contact:
Re: Thread Local Storage
Thanks for writing that article sortie!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.
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
Sortie,
Thanks for writing all that. Tremendously helpful not just for OS dev, but also for standard C library implementation.
Thanks for writing all that. Tremendously helpful not just for OS dev, but also for standard C library implementation.
Developer of libc11
- max
- Member
- Posts: 616
- Joined: Mon Mar 05, 2012 11:23 am
- Libera.chat IRC: maxdev
- Location: Germany
- Contact:
Re: Thread Local Storage
Finally implemented TLS in Ghost today. Thanks a lot again sortie.
I have a question though, you use this calculation for the alignment: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?
I have a question though, you use this calculation for the alignment:
Code: Select all
max(master_tls_alignment, alignof(struct uthread));
Also, I made this little visualization, is it correct & maybe helpful for the wiki?