diff --git a/Userland/Libraries/LibPthread/semaphore.cpp b/Userland/Libraries/LibPthread/semaphore.cpp index 81564b1422..d60d43fc1e 100644 --- a/Userland/Libraries/LibPthread/semaphore.cpp +++ b/Userland/Libraries/LibPthread/semaphore.cpp @@ -93,15 +93,19 @@ int sem_trywait(sem_t* sem) { u32 value = AK::atomic_load(&sem->value, AK::memory_order_relaxed); u32 count = value & ~POST_WAKES; - if (count == 0) - return EAGAIN; + if (count == 0) { + errno = EAGAIN; + return -1; + } // Decrement the count without touching the flag. u32 desired = (count - 1) | (value & POST_WAKES); bool exchanged = AK::atomic_compare_exchange_strong(&sem->value, value, desired, AK::memory_order_acquire); - if (exchanged) [[likely]] + if (exchanged) [[likely]] { return 0; - else - return EAGAIN; + } else { + errno = EAGAIN; + return -1; + } } // https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html