查看 pthread_*
函数的文档,例如 pthread_rwlock_destroy
和许多其他人,文档是这样写的:
RETURN VALUE
If successful, the pthread_rwlock_destroy() and pthread_rwlock_init() functions shall return zero; otherwise, an error number shall be returned to indicate the error.
The [EBUSY] and [EINVAL] error checks, if implemented, act as if they were performed immediately at the beginning of processing for the function and caused an error return prior to modifying the state of the read-write lock specified by rwlock.
这表示如果出现错误,错误编号 将被返回。然后,它解释了错误代码:
ERRORS
The pthread_rwlock_destroy() function may fail if:
[EBUSY]
The implementation has detected an attempt to destroy the object referenced by rwlock while it is locked.
...
其中没有提及返回的是 EBUSY
本身还是 -EBUSY
。当函数返回错误代码时,我几乎在所有地方看到它们返回 -E*****
。
这是否意味着 pthread_*
函数也遵循这个约定?我应该根据 -EBUSY
还是 EBUSY
本身检查返回值?
在同一主题上,他们会将 EBUSY
存储在 errno
还是 -EBUSY
中?
最佳答案
它们返回正的错误代码。应用程序不可见的内容返回否定的错误代码。这是内核的实现细节。
关于c - pthread 错误号 : negated or not?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15507123/