[v1] test: thread: Use `pthread_testcancel()`
diff mbox series

Message ID 20250310170318.185249-1-barnabas.pocze@ideasonboard.com
State Accepted
Headers show
Series
  • [v1] test: thread: Use `pthread_testcancel()`
Related show

Commit Message

Barnabás Pőcze March 10, 2025, 5:03 p.m. UTC
`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@ideasonboard.com>
---
 test/threads.cpp | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

Comments

Jacopo Mondi March 17, 2025, 5:58 p.m. UTC | #1
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@ideasonboard.com>

Nice

Reviewed-by: Jacopo Mondi <jacopo.mondi@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);
> +		pthread_testcancel();
>
>  		cancelled_ = false;
>  	}
> --
> 2.48.1
>
Kieran Bingham March 17, 2025, 9:55 p.m. UTC | #2
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@ideasonboard.com>
> 
> Nice
> 
> Reviewed-by: Jacopo Mondi <jacopo.mondi@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@ideasonboard.com>

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

Patch
diff mbox series

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);
+		pthread_testcancel();
 
 		cancelled_ = false;
 	}