C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fix bad thread_local codegen (using an attribute?)

From: Levo D <levoplusplusio_at_[hidden]>
Date: Fri, 23 Jan 2026 03:14:00 +0000
On Thu, Jan 22, 2026 at 08:45:50AM -0800, Thiago Macieira via Std-Proposals wrote:
> On Thursday, 22 January 2026 01:26:44 Pacific Standard Time M.P. via Std-
> Proposals wrote:
> > The `constinit` keyword sounds like exactly what you're looking for.
> > It's been available since C++20.
>
> That forces you to write code that must be initialised at compile time (stored
> in the .tdata section if not zeroes), but it's not sufficient for the problem.
> To "solve" this problem of initialisation, all accesses to the variable must
> see the initialisation. And if the variable is used over multiple TUs, then it
> needs to be inline.
>
> Given most code is PIC, I don't see much value in accessing the variable
> directly. Make it static in one TU and add an accessor function.

That'd be trading a call to an initialization function with a call to an accessor.

I’m surprised there’s no way to say this must be initialized when you create a thread, so I can avoid calls at the call site. I’ll stick to my __thread workaround

Received on 2026-01-23 03:14:01