Can you use thread local variables inside a class or structure

后端 未结 9 1974
名媛妹妹
名媛妹妹 2020-12-30 23:34

Like this.

struct some_struct
{
 // Other fields
 .....
 __thread int tl;
}

I\'m trying to do that but the compiler is giving me this error

9条回答
  •  遥遥无期
    2020-12-31 00:33

    You can also specify the struct itself as thread local. For example;

    #include 
    
    thread_local struct gl_i_t{
        int a; 
        int b;
    }GL_i_t;
    

    Then you can use GL_i_t variables inside thread.

提交回复
热议问题