Subject: Re: bug#38632: 27.0.50; Emacs process name is changed permanently upon creating a named thread

From: Eli Zaretskii <[email-masked]>
Date: Wed, 18 Dec 2019 17:53:49 +0200

> From: Robert Pluim <[email-masked]>
> Cc: Ihor Radchenko <[email-masked]>,  [email-masked]
> Date: Wed, 18 Dec 2019 10:05:58 +0100
> 
>     Eli> I think, instead of calling prctl in systhread.c, we should call
>     Eli> pthread_set_name_np, and the configure-time test for prctl should be
>     Eli> replaced with a test for pthread_set_name_np.
> 
> Would it not be easier to call prctl in the context of the created
> thread? That way it deals with the name length issues for us:
> pthread_setname_np fails if strlen(name) >= 16, wherease prctl
> truncates.

AFAIU, prctl is Linux-specific, whereas pthread_setname_np is
supported on other Posix platforms that provide pthreads.  Also, prctl
has another disadvantage, in that it requires you to pass the name to
the thread being created, or put it in some global.  OTOH, truncating
a string is not exactly rocket science, we can do that ourselves
before calling the API.

(Btw, the limitation is 16 bytes, including the terminating null, so
truncation needs to be clever about non-ASCII characters, and I wonder
what does prctl do when 15 bytes end in the middle of a multibyte
sequence.)