线程本地存储 (TLS) - 编译器错误
我声明了一个变量:
static __thread int a;
我收到以下错误:
fatal error (dcc:1796): 指定的目标环境不支持 __thread
我该如何解决此问题?我应该在 make 文件中启用一些标志吗?
我正在使用 windriver 编译器(为 powerpc 编译)。我提到了类似的问题,但无法弄清楚。
基本上我正在尝试制作可重入函数。任何建议都会有很大帮助。
我可以通过包含 pthread.h 来做什么吗?
谢谢。
I have declared a variable:
static __thread int a;
I am getting the following error:
fatal error (dcc:1796): __thread not supported in the specified target environment
How can I resolve this? Should I enable some flags in make file?
I am on windriver compiler(compiling for powerpc). I referred to similar questions but unable to figure out.
Basically I am trying to make re-entrant functions. Any suggestion would be of great help.
Is there anything I can by including pthread.h?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
__thread 是 gcc 扩展,它不适用于所有平台。如上所述,您可以使用 pthread_setspecic/ pthread_getspecic,有一个来自 man 的示例:
但是正如我看到的,您正在尝试创建可重入函数,可重入函数不应该保存静态非常量数据。
__thread is gcc extension which is not working on all platform. As mentioned above you could use pthread_setspecific/ pthread_getspecific, there is an example from man:
But as I see you are trying to make re-entrant functions, reentrant function should not hold static non-constant data.
__thread
是一个扩展。完成类似事情的 POSIX 线程接口是pthread_getspecific
和pthread_setspecific
__thread
is an extension. The POSIX thread interfaces to accomplish similar things arepthread_getspecific
andpthread_setspecific