Thread Local Storage

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Thread Local Storage

Post 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!
User avatar
eryjus
Member
Member
Posts: 286
Joined: Fri Oct 21, 2011 9:47 pm
Libera.chat IRC: eryjus
Location: Tustin, CA USA

Re: Thread Local Storage

Post 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. :oops:

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
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Thread Local Storage

Post 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.
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Thread Local Storage

Post 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.
:mrgreen: <3
User avatar
Arto
Member
Member
Posts: 44
Joined: Wed May 15, 2013 5:49 pm
Location: Berlin
Contact:

Re: Thread Local Storage

Post by Arto »

Sortie,

Thanks for writing all that. Tremendously helpful not just for OS dev, but also for standard C library implementation.
Developer of libc11
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Thread Local Storage

Post 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?

Image
Post Reply