Can you use thread local variables inside a class or structure

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

    According to the old Petzold book 'Programming Windows' (page 1241) you mark a variable as thread local by using the keywords: __declspec (thread). So for instance: __declspec (thread) int iGlobal = 1;

    I doubt this could be done in a class though. You can also make the variable static too. [edit] just realized you are probably not running on windows... So I guess for anyone who needs an windows answer, this may be relevant.

提交回复
热议问题