Deutsch   English   Français   Italiano  
<v2stas$2tpdk$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: C23 thoughts and opinions - why so conservative?
Date: Sat, 25 May 2024 16:41:31 +0200
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <v2stas$2tpdk$1@dont-email.me>
References: <v2l828$18v7f$1@dont-email.me> <20240523171911.00002f5a@yahoo.com>
 <v2o7re$1tlge$1@dont-email.me> <20240524003424.0000590a@yahoo.com>
 <v2qddg$2d33b$1@dont-email.me> <v334O.70055$5dk1.69613@fx10.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 25 May 2024 16:41:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="5acf865375c1c1cdc2a566d884dbbc5b";
	logging-data="3073460"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/5yoQnlMqf+eOxiwCNtxwnAJgZGwJ0YpA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0qz3UjGX3Qs0q6GqXc2NXXrOyDE=
In-Reply-To: <v334O.70055$5dk1.69613@fx10.iad>
Content-Language: en-GB
Bytes: 3062

On 24/05/2024 18:16, Scott Lurndal wrote:
> David Brown <david.brown@hesbynett.no> writes:
>> On 23/05/2024 23:34, Michael S wrote:
>>> On Thu, 23 May 2024 22:10:22 +0200
>>> David Brown <david.brown@hesbynett.no> wrote:
> 
>>> _Thread_local is a special-purpose thing, probably not applicable at
>>> all for programming of small embedded systems, which nowadays is the
>>> only type of programming in C that I do for money rather than as hobby.
>>
>> I have never seen the point of it either.  Why would anyone want a
>> variable that exists for /all/ threads in a program, but independently
>> per thread?
> 
> Very common in kernel programming (e.g. the use of '%gs' in x86_linux)
> as a pointer to the 'per-cpu' data structure.
> 
> We use thread local  to implement 'self' methods in certain
> classes (so rather than passing pointers around, one can
> simply call class::self() to get a pointer to the
> class for each thread.
> 
> class c_processor {
>   ...
>      /**
>       * Per-thread value of the processor object.
>       */
>      static __thread c_processor *p_this;
>   ...
> 
> public:
>      c_processor(c_system *, c_logger *, processor_number_t, bool);
>      ~c_processor(void);
>      
>      static c_processor *self(void) { return p_this; }
> 
> ...
> 
> 
> 
> 
>     c_processor *pp = c_processor::self().

I can see that.  But you only want a few of these, and it is typically 
in very low-level code that is full of compiler-specific or 
target-specific stuff anyway.  Such things could be compiler extensions 
or other implementation-specific features.

After all, "thread_local" is useless for the vast majority of OS's 
(counting numbering of OS's, not number of users).  You can't use it 
unless the C (or in this case, C++) implementation has support for the 
OS in the library and compiler.