c - 线程局部变量和 fs 段

标签 c linux multithreading gcc x86-64

我正在像这样从我的代码中的线程局部变量中读取数据,

// tid_local is declared as __thread int tid_local;
long tid = tid_local

查看反汇编代码,我看到了这样的东西,我怀疑这是通过读取tid_local 来分配tid 的指令。

movslq %fs:0xfffffffffffffffc,%rbx

现在我的问题是,这是否真的是执行此操作的指令,即从本地线程变量读取,以及 gcc 是否始终使用 fs 段来存储线程本地变量。这应该如何工作?

最佳答案

是的,这很可能是正确的指示。来自 gcc manual :

-mtls-direct-seg-refs

-mno-tls-direct-seg-refs

Controls whether TLS variables may be accessed with offsets from the TLS segment register (%gs for 32-bit, %fs for 64-bit), or whether the thread base pointer must be added. Whether or not this is legal depends on the operating system, and whether it maps the segment to cover the entire TLS area.

编辑 这是@janneb 在评论中建议的一个很好的链接:http://www.akkadia.org/drepper/tls.pdf

关于c - 线程局部变量和 fs 段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8747070/

相关文章:

.net - 多线程列表中的SyncLock仍然抛出ArgumentException

c++ - 在 Qt 中设置 GUI 线程的优先级

c# - 等待动态创建的任务直到它们完成

java - 将 TIFF 转换为 JPEG 在 Linux 中不起作用 - 无法为此操作呈现 RenderedOp

php - 使用php远程连接到mysql服务器

C 递归 - 将数字的每个数字加 1,除了数字 9 为 0

c++ - 错误是什么?Q-确定并打印给定 n 值的以下谐波级数之和。(1+1/2+1/3+........+1/n)

c - C 中的 int foo (int argc, ...) vs int foo() vs int foo(void)

c - 如何创建指向列表中每个成员的指针

linux - 在 linux 脚本上更改目录