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

Jacopo Mondi jacopo.mondi at ideasonboard.com
Mon Mar 17 18:58:55 CET 2025


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


More information about the libcamera-devel mailing list