将使用全局结构指针作为线程本地存储的原因是什么

发布于 2025-02-10 10:07:59 字数 254 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2025-02-17 10:07:59

我猜想您显示的代码片段是为了设置初始线程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 is main), 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文