public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Rachid Koucha <rachid.koucha@gmail.com>, libc-alpha@sourceware.org
Subject: Re: About pthread_yield() implementation
Date: Mon, 21 Dec 2020 14:57:39 -0300	[thread overview]
Message-ID: <feb6d1dd-cd02-d8ce-6335-1af201a7ddc8@linaro.org> (raw)
In-Reply-To: <9d6ae6c9-0f57-94dc-2a4d-64d63a44a117@gmail.com>



On 20/12/2020 16:03, Rachid Koucha via Libc-alpha wrote:
> Hi,
> 
> Answering a question about pthread_yield() on StackOverflow web site, I
> realize that there is a possible implementation bug for this function
> (in the GLIBC 2.31 at least):
> 
> The source code of the service is:
> 
> |/* With the 1-on-1 model we implement this function is equivalent to
> the 'sched_yield' function. */ int pthread_yield (void) { return
> sched_yield (); } |
> 
> ||||But this results in a unusual pthread API behavior which *may be an
> implementation bug* as it returns directly the result of
> /sched_yield()/. Like most of the Linux system calls, the latter returns
> -1 and sets *errno* if it fails (even if the manual specifies that it
> actually never returns in error). So, theoretically, this makes
> /pthread_yield()/ return -1 and set *errno* in case of error although
> the pthread API usually returns 0 if successful and the error number in
> case of error (*errno* is not supposed to be set). So, the manual is
> wrong or at least does not comply with the GLIBC's implementation when
> it describes the returned value as:
> 
> RETURN VALUE
> 
>     On success, pthread_yield() returns 0; on error, it returns an error
>     number.

Indeed, it should be calling thrd_yield through INTERNAL_SYSCALL_CALL
(similar to thrd_yield).  It should not happen in a realword because
the Linux syscall never fails, but it is worth to fix.  I will check
this out.

      reply	other threads:[~2020-12-21 17:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-20 19:03 Rachid Koucha
2020-12-21 17:57 ` Adhemerval Zanella [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=feb6d1dd-cd02-d8ce-6335-1af201a7ddc8@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=rachid.koucha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).