Can you use thread local variables inside a class or structure

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

    C11 standard Section 6.7.1 Paragraph 2

    At most, one storage-class specifier may be given in the declaration specifiers in a declaration, except that _Thread_local may appear with static or extern.120)

    C11 standard Section 6.7.1 Paragraph 3

    In the declaration of an object with block scope, if the declaration specifiers include _Thread_local, they shall also include either static or extern. If _Thread_local appears in any declaration of an object, it shall be present in every declaration of that object.

提交回复
热议问题