What is thread local storage? Why we need it?

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

    Let's supposed you are working in Ada. In your Ada program you define a task (thread) that includes a [static] variable that can only be accessed by the task. You now create multiple instances of your task. Then you need a copy of that [static] variable for each task.

    That's where your implementation could use Thread Local Storage. In other words, it is a static area of memory that gets copied for each thread in a program.

    As an alternative to TLS, a thread could allocate such storage at the top of the stack.

提交回复
热议问题