c - pthread 错误号 : negated or not?

标签 c pthreads errno error-code

查看 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/

相关文章:

c++ - 虚方法和this指针

Python socket.error : [Errno 111] Connection refused

c++ - linux底层如何拦截键盘输入?

c - 如何手动设置等于 NaN 的 float 的位值?

c - Pthread condvar 习语

c++ - 当g++静态链接pthread时,导致段错误,为什么?

c++ - 调用 execl 时找不到 Grep

c - C 库应该如何管理错误?

c - 这个是casting吗,这个是什么and运算符

c - Valgrind 和 GDB 替代 Mac?