質問

Looking at documentation for pthread_* functions such as pthread_rwlock_destroy and many others, this is how the documentation is worded:

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.

This says that in case of error, an error number shall be returned. Then, it explains the error codes:

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.
...

Which doesn't mention whether EBUSY itself is returned or -EBUSY. Almost everywhere I see when functions return an error code, they return -E*****.

Does that mean pthread_* functions also follow this convention? Should I check the return value against -EBUSY or EBUSY itself?

On the same subject, would they store EBUSY in errno or -EBUSY?

役に立ちましたか?

解決

They return the error codes which are positive. Nothing visible to applications returns negated error codes. That's an implementation detail of the kernel.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top