[PATCH v1] test: thread: Use `pthread_testcancel()`

Kieran Bingham kieran.bingham at ideasonboard.com
Mon Mar 17 22:55:42 CET 2025


Quoting Jacopo Mondi (2025-03-17 17:58:55)
> 
> On Mon, Mar 10, 2025 at 06:03:18PM +0100, Barnabás Pőcze wrote:
> > `pthread_testcancel()` is a guaranteed cancellation point,
> > specifically for testing if cancellation has been requested,
> > so use it.
> >
> > Signed-off-by: Barnabás Pőcze <barnabas.pocze at ideasonboard.com>
> 
> Nice
> 
> Reviewed-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>
> 
> > ---
> >  test/threads.cpp | 8 +-------
> >  1 file changed, 1 insertion(+), 7 deletions(-)
> >
> > diff --git a/test/threads.cpp b/test/threads.cpp
> > index 8d6ee1510..c00d95a41 100644
> > --- a/test/threads.cpp
> > +++ b/test/threads.cpp
> > @@ -52,14 +52,8 @@ protected:
> >       {
> >               cancelled_ = true;
> >
> > -             /*
> > -              * Cancel the thread and call a guaranteed cancellation point
> > -              * (nanosleep).
> > -              */
> >               pthread_cancel(pthread_self());
> > -
> > -             struct timespec req{ 0, 100*000*000 };
> > -             nanosleep(&req, nullptr);

I guess this delay was uncessary ...

pthread_testcancel() sounds like the right thing from the man page
though!

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> > +             pthread_testcancel();
> >
> >               cancelled_ = false;
> >       }
> > --
> > 2.48.1
> >


More information about the libcamera-devel mailing list