[PATCH v2] Add threaded test of sem_trywait

Florian Weimer fweimer@redhat.com
Fri Nov 29 20:07:19 GMT 2024


* Joseph Myers:

> diff --git a/sysdeps/pthread/tst-sem19.c b/sysdeps/pthread/tst-sem19.c
> new file mode 100644
> index 0000000000..9ef461e008
> --- /dev/null
> +++ b/sysdeps/pthread/tst-sem19.c

> +  TEST_COMPARE (ret, -1);
> +  TEST_COMPARE (errno, EAGAIN);
> +  xpthread_mutex_unlock (&lock);
> +  /* The other thread now takes the lock, calls sem_post and releases
> +     the lock.  */
> +  for (;;)
> +    {
> +      errno = 0;
> +      ret = sem_trywait (&sem);
> +      if (ret == 0)
> +	break;
> +      TEST_COMPARE (errno, EAGAIN);
> +    }
> +  xpthread_join (th);

The busy-waiting loop could call sched_yield, but it's not required.
Either way:

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian



More information about the Libc-alpha mailing list