OSDev.org
https://forum.osdev.org/

Thread Local Storage
https://forum.osdev.org/viewtopic.php?f=8&t=28739
Page 1 of 1

Author:  sortie [ Mon Nov 17, 2014 5:33 pm ]
Post subject:  Thread Local Storage

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!

Author:  eryjus [ Tue Nov 18, 2014 1:23 pm ]
Post subject:  Re: Thread Local Storage

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.

Author:  sortie [ Tue Nov 18, 2014 2:30 pm ]
Post subject:  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.

Author:  max [ Wed Nov 19, 2014 2:22 am ]
Post subject:  Re: Thread Local Storage

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

Author:  Arto [ Sat Nov 22, 2014 12:00 am ]
Post subject:  Re: Thread Local Storage

Sortie,

Thanks for writing all that. Tremendously helpful not just for OS dev, but also for standard C library implementation.

Author:  max [ Fri Mar 06, 2015 4:04 pm ]
Post subject:  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:
Code:
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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/