Re: [PATCH v5 08/24] util: add API to fetch the current thread name

Paolo Bonzini <[email protected]>
Newsgroups org.nongnu.qemu-rust,org.nongnu.qemu-devel
Message-ID <[email protected]>
On 1/9/26 12:56, Daniel P. Berrangé wrote:
> On Fri, Jan 09, 2026 at 12:49:20PM +0100, Paolo Bonzini wrote:
>> On 1/8/26 18:03, Daniel P. Berrangé wrote:
>>> +static __thread char namebuf[PTHREAD_MAX_NAMELEN_NP];
>>
>> ... you can instead of the previous patch, add a constructor here that just
>> sets namebuf to "main" with strcpy.
> 
> How about just a static initializer
> 
>    static __thread char namebuf[PTHREAD_MAX_NAMELEN_NP] = { 'm', 'a', 'i', 'n', '\0' };
> 
> or is there some interaction with __thread that makes that undesirable ?

This would break here:

     if (namebuf[0] != '\0') {
         return namebuf;
     }

and every thread would have "main" as the name, because static 
initializers for __thread apply to all threads.

Thanks,

Paolo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.