Why do semaphores use errno while mutexes return the error directly?

92 Views Asked by At

The docs for pthread_mutex_trylock (and friends) say

If successful, the pthread_mutex_lock() and pthread_mutex_unlock() functions shall return zero; otherwise, an error number shall be returned to indicate the error.

Cool. Makes sense, If we're doing try_lock we probably want to access the result to check if it locked or not. Nice and fast.

But for some reason sem_trywait returns -1 on error and sets errno! Not only this, but instead of doing EBUSY, we get EAGAIN!

This seems like a weird and arbitrary design difference. What are the reasons for it?

0

There are 0 best solutions below