public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: Jon Turney <jturney@sourceware.org>
Cc: Cygwin Patches <cygwin-patches@cygwin.com>
Subject: Re: [newlib-cygwin] Cygwin: Set threadnames with SetThreadDescription()
Date: Fri, 29 Jul 2022 20:28:55 +0200	[thread overview]
Message-ID: <YuQm5xcBC+1LJSJk@calimero.vinschen.de> (raw)
In-Reply-To: <78af80e5-baed-5ebb-314f-99d13f2a25ca@sourceware.org>

On Jul 29 15:14, Jon Turney wrote:
> On 29/07/2022 12:58, Corinna Vinschen wrote:
> > Hi Jon,
> > 
> > On Jul 29 11:01, Jon TURNEY via Cygwin-cvs wrote:
> > > https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d4689b99c68628d9ec2fc1ac7884906ddbf6a2fc
> > > 
> > > commit d4689b99c68628d9ec2fc1ac7884906ddbf6a2fc
> > > Author: Jon Turney <jon.turney@dronecode.org.uk>
> > > Date:   Thu May 19 17:27:39 2022 +0100
> > > 
> > >      Cygwin: Set threadnames with SetThreadDescription()
> > >      [...]
> > > +      /* SetThreadDescription only exists in a wide-char version, so we must
> > > +	 convert threadname to wide-char.  The encoding of threadName is
> > > +	 unclear, so use UTF8 until we know better. */
> > > +      int bufsize = MultiByteToWideChar (CP_UTF8, 0, threadName, -1, NULL, 0);
> > > +      WCHAR buf[bufsize];
> > > +      bufsize = MultiByteToWideChar (CP_UTF8, 0, threadName, -1, buf, bufsize);
> > 
> > I think this is wrong.  The function should use stock mbstowcs instead
> > to get the externally used encoding.  Think of SetThreadName called with
> > program_invocation_short_name in pthread::thread_init_wrapper, or called
> > from pthread_setname_np with an externally provided thread name.  This
> > thread name will use the locale of the application code it's called by.
> 
> I'm not sure.
> 
> The linux manpage for pthread_setname_np() says "The thread name is a
> meaningful C language string", which I think means it's ASCII-encoded, not
> locale-encoded.

I think this only means, it's a NUL-terminated string. "Meaningful" is
just trying to nudge developers into using meaningful names, not
something like "blurb".

> (The solaris manpage explicitly says that the thread name is utf8 encoded)

Ok, that's an interesting point.

> The encoding for program_invocation_short_name was also unclear to me.
> (It's the same as argv[0], so I guess it's in whatever encoding the
> filesystem uses, which doesn't have to match the process locale encoding)
> 
> Expecting this function to work with non-ASCII names seems optimistic :)

Well, for Linux it's certainly just an arbitrary, NUL-terminated byte
stream, but yeah, it's certainly the only portable way to expect
the portable codeset.

Anyway, feel free to just keep the code as is.  We're typically using
UTF-8 anyway and people switching to one of the legacy codesets are
supposed to know what they are doing.


Corinna

       reply	other threads:[~2022-07-29 18:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220729110147.4E6F43858424@sourceware.org>
     [not found] ` <YuPLd2hlbaNwxAJ0@calimero.vinschen.de>
     [not found]   ` <78af80e5-baed-5ebb-314f-99d13f2a25ca@sourceware.org>
2022-07-29 18:28     ` Corinna Vinschen [this message]
2022-07-31 15:03       ` Jon Turney

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=YuQm5xcBC+1LJSJk@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-patches@cygwin.com \
    --cc=jturney@sourceware.org \
    /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).