Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Equivalence of sem_trywait and sem_timedwait

30 views
Skip to first unread message

Noob

unread,
May 20, 2012, 12:02:38 PM5/20/12
to
Hello,

(I'm writing a wrapper API.)

Is sem_trywait equivalent to sem_timedwait with a timespec set to 0?

I.e. is
sem_trywait(sem);
equivalent to
struct timespec spec = { 0 };
sem_timedwait(sem, &spec);

Other than the value of errno when the semaphore is already
locked (EAGAIN for trywait, ETIMEDOUT for timedwait).

http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html

Regards.

Rainer Weikusat

unread,
May 20, 2012, 4:52:18 PM5/20/12
to
Noob <root@localhost> writes:
> Is sem_trywait equivalent to sem_timedwait with a timespec set to 0?
>
> I.e. is
> sem_trywait(sem);
> equivalent to
> struct timespec spec = { 0 };
> sem_timedwait(sem, &spec);
>
> Other than the value of errno when the semaphore is already
> locked (EAGAIN for trywait, ETIMEDOUT for timedwait).

The specification suggests that this is indeed the case.
0 new messages