Re: sem_trywait(3) and sem_wait(3) can return EINTR

2018-03-28 Thread Philip Guenther
On Wed, Mar 28, 2018 at 2:14 PM, Paul Irofti  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 >lock, delayed_cancel);
>  76 _spinlock(>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


sem_trywait(3) and sem_wait(3) can return EINTR

2018-03-28 Thread Paul Irofti
Hi,

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 >lock, delayed_cancel);
 76 _spinlock(>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.

Paul