thread_local

Post Reply

Topic author
mberryman
Active Contributor
Posts: 27
Joined: Sat Sep 02, 2023 1:31 pm
Reputation: 0
Location: Colorado Springs, CO, USA
Status: Offline

thread_local

Post by mberryman » Thu Dec 28, 2023 10:40 am

When a new thread is created with pthread_create, is there anything from the image that is copied into the new thread?

Specifically, MariaDB makes extensive use of thread_local declarations and they tend to be at global scope. For example, a .h file will have: extern thread_local something* x;

Several c++ files will then include that .h file but one of them will declare the variable in its global scope. The code will then make extensive references to x->something. So far, I've been able to make use of the [get|set]specific routines to define the value of x but how do I make sure that x itself is local to each thread?


jreagan
VSI Expert
Master
Posts: 139
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: thread_local

Post by jreagan » Thu Dec 28, 2023 10:46 am

We currently do not support any of the TLS features in C++ (the release notes say that near the bottom). We've considered TLS support (it is becoming more common) but the support is quite complicated as it involves many tools (ie, not any time soon)

As for what pthread_create propagates to the next thread, I'm not sure. I'd have to read manuals, consult the code, and perhaps use my Magic 8-Ball.

Post Reply