What is thread local storage? Why we need it?

后端 未结 3 1795
鱼传尺愫
鱼传尺愫 2021-02-15 17:52

I am reading the Threads in OS concepts and i come across \"thread local storage (TLS)\". What I understood is that the TLS is similar to static or global data, but it is more u

3条回答
  •  别跟我提以往
    2021-02-15 18:06

    Static and global data are shared across all the threads. If you modified a global/static variable it is visible to all the threads. Unlike global/shared variable if you create a variable in TLS, every thread has its own copy of the variable, i.e. changes to the variable is local to the thread. Unlike global variable where an access is made through ds segment, the TLS variable are accessed using (gs/fs) segment. A good way to learn about it is to look at the disassembly generated by the compiler.

提交回复
热议问题