On 5/27/2022 12:52 AM, Petro Karashchenko wrote:
Hi,

Ok. That makes sense. But there is a strane code in sem_wait:

   if (enter_cancellation_point())
     {
#ifdef CONFIG_CANCELLATION_POINTS
       /* If there is a pending cancellation, then do not perform
        * the wait.  Exit now with ECANCELED.
        */

       errcode = ECANCELED;
       goto errout_with_cancelpt;
#endif
     }

This code in conjunction with "while ((ret = _SEM_WAIT(sem)) < 0)" seems to
be a pure "deadlock" (endless loop) in case if _SEM_WAIT is defined to
sem_wait. Or am I missing something?
This is of course when sem_wait is called while the task entered the
cancellation point already.

Best regards,
Petro

"while ((ret = _SEM_WAIT(sem)) < 0)" is not an endless loop.

ECANCEL is handled just like EINTR:  For EINTR, when the signal is received, _SEM_WAIT wakes up and returns -EINTR.  If _SEM_WAIT is called again, it does not remember that the thread was signaled; it does not return -EINTR again but behaves normally and waits for the semaphore.

ECANCEL works the same:  When a thread is canceled, _SEM_WAIT wakes up and return -ECANCELED.  If _SEM_WAIT is called it again, it does not remember that the thread was canceled; it does not return -ECANCELED again but behaves normally and waits for the semaphore.

So there is no infinite loop.


Reply via email to