What is thread local storage? Why we need it?

后端 未结 3 1957
鱼传尺愫
鱼传尺愫 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:21

    We need thread-local storage to create libraries that have thread-safe functions, because of the thread-local storage each call to a function has its copy of the same global data, so it's safe I like to point out that the implementation is the same for copy on write technique.

    in normal function with global data, the content of that data can be updated by multiple threads and make it unreliable, but in thread-local storage, you can think of it as

    "global became local when multiple access happen "

提交回复
热议问题