[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-tech
Subject:    Re: sem_trywait(3) and sem_wait(3) can return EINTR
From:       Philip Guenther <guenther () gmail ! com>
Date:       2018-03-29 1:37:58
Message-ID: CAKKmsNieB6tGHkohQKr5YFtpzez9ENNwaf7actUwBFfSbqgZog () mail ! gmail ! com
[Download RAW message or body]

On Wed, Mar 28, 2018 at 2:14 PM, Paul Irofti <paul@irofti.net> wrote:
>
> I do not know if this is expected or not, but sem_trywait(3) can and
> does return EINTR. From the manpage I got the impression that it should
> not. Should we amend the manpage or is this something to be fixed in the
> implementation?
>
>  73                 do {
>  74                         r = __thrsleep(ident, CLOCK_REALTIME, abstime,
>  75                             &sem->lock, delayed_cancel);
>  76                         _spinlock(&sem->lock);
>  77                         /* ignore interruptions other than cancelation
> */
>  78                         if (r == EINTR && (delayed_cancel == NULL ||
>  79                             *delayed_cancel == 0))
>  80                                 r = 0;
>  81                 } while (r == 0 && sem->value == 0);
>
> Lines 78--80 are the interesting ones.


Lines 69-70 are more important for sem_trywait():
     69         } else if (tryonly) {
     70                 r = EAGAIN;
     71         } else {

sem_trywait() calls _sem_wait() with tryonly=1, so it can't reach that
do{tsleep}while loop and will never return EINTR.

In the end, _sem_wait() will return EINTR only if the thread was
canceled...in which case the function that called _sem_wait() will never
return but instead call _thread_canceled() via
the LEAVE_CANCEL_POINT_INNER() macro.


Philip Guenther
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic