[英]How does pthread_self() always succeed?
When I was learning pthread, the manual says pthread_self()
always succeeds.我在学习 pthread 的时候,手册上说
pthread_self()
总是成功的。
ERRORS
错误
This function always succeeds.
此功能总是成功。
How does that happen?怎么会这样? How do we determine whether a function will always succeed?
我们如何确定一个函数是否总是会成功?
I tried to find the answer from the code, and I encounter the following code:尝试从代码中寻找答案,遇到如下代码:
# define THREAD_SELF \
({ struct pthread *__self; \
asm ("movl %%gs:%c1,%0" : "=r" (__self) \
: "i" (offsetof (struct pthread, header.self))); \
__self;})
I didn't see the field header.self
in struct pthread
, did I look into the wrong definition?我没有在
struct pthread
看到字段header.self
,我是否查看了错误的定义? And what does the %c1
mean? %c1
是什么意思? Is the input i
unused?输入
i
未使用吗?
pthread_self()
returns the identifier of the currently-running thread. pthread_self()
返回当前运行线程的标识符。 It has to be called by the "currently running thread", so that identifier must exist.它必须由“当前运行的线程”调用,因此该标识符必须存在。
How can that fail?怎么会失败呢? It's the same way that we all assume that expressions such as
x++;
这与我们都假设
x++;
等表达式的方式相同x++;
or y = x / z
can't fail.或
y = x / z
不能失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.