Can you use thread local variables inside a class or structure

后端 未结 9 2016
名媛妹妹
名媛妹妹 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:14

    gcc imposes the following restrictions on the use of __thread:

    The __thread specifier may be applied to any global, file-scoped static, function-scoped static, or static data member of a class. It may not be applied to block-scoped automatic or non-static data member.

    The __thread modifier is supported by multiple compiler. It is not inconceivable that the exact restrictions vary somewhat from compiler to compiler.

提交回复
热议问题