gpt4 book ai didi

c - pthread_self() 怎么总是成功?

转载 作者:太空宇宙 更新时间:2023-11-03 23:41:42 27 4
gpt4 key购买 nike

我学pthread的时候,手册上说pthread_self()总是成功

ERRORS

This function always succeeds.

这是怎么发生的?我们如何确定一个函数是否总是成功?

我试图从代码中寻找答案,遇到了如下代码:

# define THREAD_SELF \
({ struct pthread *__self; \
asm ("movl %%gs:%c1,%0" : "=r" (__self) \
: "i" (offsetof (struct pthread, header.self))); \
__self;})

我在struct pthread 中没有看到header.self 字段,是不是我看错了定义? %c1 是什么意思?输入 i 是否未使用?

最佳答案

pthread_self() 返回当前运行线程的标识符。它必须由“当前运行的线程”调用,因此该标识符必须存在。

怎么会失败呢?这与我们都假设 x++;y = x/z 等表达式不会失败的方式相同。

关于c - pthread_self() 怎么总是成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43779077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com