我目前正在使用pthread并从此处阅读文档:Pthread Manual Pthread Join。
但是,当我读取页面时,我看到了ERRORS,但没有找到相应的返回值,这些值将从pthread_join
返回。所以我的问题是,错误是按升序排序的(因为它可能是一个枚举器)?
答案 0 :(得分:1)
EDEADLK
等错误值是通过包含<errno.h>
头文件定义的宏。
示例:
#include <pthread.h>
#include <errno.h>
...
int retval = pthread_join( threadID, NULL );
if ( retval == EDEADLK )
{
// error-handling code for deadlock
}
else if ( retval == EINVAL )
{
// error-handling code for invalid thread id
}
else if ( retval == ESRCH )
{
// error-handling code for no such thread id
}
请注意,上述代码仅适用于Linux,因为唯一的错误编号specified by POSIX for pthread_join()
为EDEADLCK
。
每the POSIX standard for error numbers,(与您的问题特别相关的粗体部分):
2.3错误号
大多数功能都可以提供错误编号。每种方式的手段 函数提供的错误号在其描述中指定。
某些函数在通过访问的变量中提供错误号 符号
errno
,通过包含<errno.h>
标题定义。errno
的值只应在指示时进行检查 由函数的返回值有效。这卷中没有任何功能 POSIX.1-2008应将errno
设置为零。对于进程的每个线程,errno
的值不受函数调用或影响 其他线程对errno
的分配。某些函数直接返回错误编号作为函数值。这些函数返回零值表示成功。
如果在处理函数调用时出现多个错误,则任何一个错误 可以返回可能的错误,因为检测顺序是 未定义。
实施可能会支持未包含的其他错误 列表,可能会在情况下生成此列表中包含的错误 除了这里描述的那些,或者可能包含扩展或 阻止某些错误发生的限制。
每个参考页面上的ERRORS部分指定了哪个错误 所有实施都应检测条件(&#34;应失败&#34;)和 可以选择性地通过实现来检测(&#34;可能会失败&#34;)。如果 未检测到错误情况,请求的操作应为 成功的。如果检测到错误条件,则请求执行操作 除非另有说明,否则可能已部分执行。
实现可能会生成此处列出的错误号 除了那些以外的情况,当且仅当所有这些情况 错误条件始终可以与错误相同地处理 本卷POSIX.1-2008中描述的条件。 实现不应从一个生成不同的错误号 此卷POSIX.1-2008需要一个错误条件 在本卷POSIX.1-2008中描述,但可能会产生额外的 错误,除非明确禁止某个特定功能。
每项实施应在符合性文件中记录, 其中定义的每个可选条件的情况 检测到POSIX.1-2008。一致性文档也可能包含 声明一个或多个可选错误条件不是 检测
某些与线程相关的函数不允许返回错误 代码[EINTR]。如果适用,则在错误部分中说明 在各个功能页面上。
以下宏名称标识可能的错误编号,在本卷的具体定义的函数的上下文中 POSIX.1-2008;这些一般性描述更准确地定义于 返回它们的函数的错误部分。只有这些 宏名称应该在程序中使用,因为它的实际值 错误号未指定。本节中列出的所有值均应 除非如下所述,否则是唯一的。所有这些宏的值 应在Base中定义的
<errno.h>
标题中找到 POSIX.1-2008的定义量。实际值未指定 按此数量的POSIX.1-2008。[E2BIG] Argument list too long. The sum of the number of bytes used by the new process image's argument list and environment list is greater than the system-imposed limit of {ARG_MAX} bytes. or: Lack of space in an output buffer. or: Argument is greater than the system-imposed maximum. [EACCES] Permission denied. An attempt was made to access a file in a way forbidden by its file access permissions. [EADDRINUSE] Address in use. The specified address is in use. [EADDRNOTAVAIL] Address not available. The specified address is not available from the local system. [EAFNOSUPPORT] Address family not supported. The implementation does not support the specified address family, or the specified address is not a valid address for the address family of the specified socket. [EAGAIN] Resource temporarily unavailable. This is a temporary condition and later calls to the same routine may complete normally. [EALREADY] Connection already in progress. A connection request is already in progress for the specified socket. . . .