From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Andrew Pinski <pinskia@gmail.com>,
GNU C Library <libc-alpha@sourceware.org>
Subject: Re: swapcontext happening on different threads
Date: Tue, 12 Mar 2024 12:48:20 +0000 [thread overview]
Message-ID: <ZfBPFFhyP0upAqCv@arm.com> (raw)
In-Reply-To: <CA+=Sn1mq6CmyQj-bw5=-uNQfzjO+8Qc2LREUFusx0yRcyj-ruQ@mail.gmail.com>
The 03/12/2024 00:24, Andrew Pinski wrote:
> Reference https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65712 .
>
> I am not 100% sure if this is a valid thing to do.
> But take the code in the referenced GCC bug report. Currently since
> pthread_self is marked as const, if you swap to a different context
> and then have that context be swapped on a different thread, you
> might/will get the old value of pthread_self in some cases.
>
> Is this well defined or is this a corner case that was not expected. I
> don't see anywhere in the older versions of POSIX that explain what
> would happen if you do that. And glibc's documentation does not talk
> about this case either.
>
> It would be useful if the documentation talked about this either way.
yeah.
my view is that resuming on a different thread is invalid.
(tls address or other thread specific state cached on the
stack is broken).
there are known users who switch between threads via swapcontext,
i think they are on their own to ensure things work since they
are in undefined land (maybe the compiler could help with
appropriate barriers).
otoh const pthread_self is theoretically wrong even without
swapcontext breaking it: the compiler can cache const func
output into a per-process global variable as far as i can
tell. (iirc there were bugzilla discussions before that
attribute const should not allow exception return or different
return values in different threads. btw this affects
__errno_location too in glibc)
next prev parent reply other threads:[~2024-03-12 12:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 7:24 Andrew Pinski
2024-03-12 12:48 ` Szabolcs Nagy [this message]
2024-03-12 13:47 ` Florian Weimer
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=ZfBPFFhyP0upAqCv@arm.com \
--to=szabolcs.nagy@arm.com \
--cc=libc-alpha@sourceware.org \
--cc=pinskia@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).