将使用全局结构指针作为线程本地存储的原因是什么
typedef struct Test
{
}Test;
//global struct
Test t;
static __thread *tTLS = &t;
有人可以解释我们试图用上述代码实现什么吗?用户赛可以是什么?
在这里,我们有一个全局结构,指向它的指针用作TLS(线程本地存储)。因此,无论如何,我们都有一个带有线程的全局结构地址,为什么我们可能再次需要其指针作为TLS?
示例将有所帮助。
typedef struct Test
{
}Test;
//global struct
Test t;
static __thread *tTLS = &t;
Can someone explain what are we trying to achieve with above code? what can be the usecases?
here we have a global structure and pointer to it is used as a TLS (thread local storage). So we anyways have a global structure address with the thread why we may need its pointer again as a TLS?
The example would help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜想您显示的代码片段是为了设置初始线程的
ttls
的值(其线程过程为main ),仅。在所有其他线程中,
ttls
将被更改为指向其他结构。您可以通过显示至少一个线程过程的代码来确认此猜测,而不是
main
。I'm guessing that the code fragment you showed is meant to set up the value of
tTLS
for the initial thread (the thread whose thread procedure ismain
), only. In all the other threads,tTLS
will be changed to point to some other struct.You could confirm this guess by showing the code of at least one thread procedure other than
main
.