* About pthread_yield() implementation
@ 2020-12-20 19:03 Rachid Koucha
2020-12-21 17:57 ` Adhemerval Zanella
0 siblings, 1 reply; 2+ messages in thread
From: Rachid Koucha @ 2020-12-20 19:03 UTC (permalink / raw)
To: libc-alpha
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.
Regards,
Rachid.
||
||
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: About pthread_yield() implementation
2020-12-20 19:03 About pthread_yield() implementation Rachid Koucha
@ 2020-12-21 17:57 ` Adhemerval Zanella
0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2020-12-21 17:57 UTC (permalink / raw)
To: Rachid Koucha, libc-alpha
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-21 17:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20 19:03 About pthread_yield() implementation Rachid Koucha
2020-12-21 17:57 ` Adhemerval Zanella
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).