tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
On 10/7/2024 9:03 AM, jseigh wrote:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
I don't think so. Fwiw, a while back I was trying to port one of my
thread local memory allocators that used pthread tss to pure C++ and
gave up. It has important logic in its destructor. The function pointer
in: pthread_key_create ala tss_create. So, shit happens! ;^o
On 10/7/2024 9:03 AM, jseigh wrote:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
I don't think so. Fwiw, a while back I was trying to port one of my
thread local memory allocators that used pthread tss to pure C++ and
gave up. It has important logic in its destructor. The function pointer
in: pthread_key_create ala tss_create. So, shit happens! ;^o
On 10/7/24 15:50, Chris M. Thomasson wrote:
On 10/7/2024 9:03 AM, jseigh wrote:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
I don't think so. Fwiw, a while back I was trying to port one of my
thread local memory allocators that used pthread tss to pure C++ and
gave up. It has important logic in its destructor. The function
pointer in: pthread_key_create ala tss_create. So, shit happens! ;^o
I suppose you could use a thread local map with logic on top of that.
I probably don't need it. I was using it in C to get notification
when a thread exited for clean up of any resources the thread had
not explicitly cleaned up. I could come up with a thread exit
listener if need be.
Joe Seigh
On 10/7/24 15:50, Chris M. Thomasson wrote:
On 10/7/2024 9:03 AM, jseigh wrote:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
I don't think so. Fwiw, a while back I was trying to port one of my
thread local memory allocators that used pthread tss to pure C++ and
gave up. It has important logic in its destructor. The function
pointer in: pthread_key_create ala tss_create. So, shit happens! ;^o
I suppose you could use a thread local map with logic on top of that.
I probably don't need it. I was using it in C to get notification
when a thread exited for clean up of any resources the thread had
not explicitly cleaned up.
I could come up with a thread exit
listener if need be.
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
Joe Seigh
Am 07.10.2024 um 18:03 schrieb jseigh:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
Joe Seigh
A thread_local object declared globally is constructed when a new
thread starts and destructed when a thread ends. A thread_local
object declared locally is constructed when the code comes across
its declaration and destructed when the thread ends.
So, psuedo code here:
void ct_thread()
{
thread_local per_thread_data();
}
If I create a single thread, then I should get one ctor and
one dtor with the dtor being called within the thread, right?
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
jseigh writes:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
Not in C++ proper, but gcc supports it:
https://gcc.gnu.org/onlinedocs/gcc/Thread-Local.html
Am 08.10.2024 um 08:29 schrieb Chris M. Thomasson:
So, psuedo code here:
void ct_thread()
{
thread_local per_thread_data();
}
If I create a single thread, then I should get one ctor and
one dtor with the dtor being called within the thread, right?
per_thread_data is created only if the thread comes across the
definition. If you need reliable behaviour according to each
created thread make per_thread_data global.
Am 08.10.2024 um 14:26 schrieb Sam:
jseigh writes:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
Not in C++ proper, but gcc supports it:
https://gcc.gnu.org/onlinedocs/gcc/Thread-Local.html
This doesn't help you if you want to get notified when a thread-local
object is being destructed.
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
Joe Seigh
On 10/7/24 12:03, jseigh wrote:[...]
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
I figured something out so all good I think.
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
On 10/7/24 12:03, jseigh wrote:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
Joe Seigh
I figured something out so all good I think.
On 10/8/24 17:03, jseigh wrote:
On 10/7/24 12:03, jseigh wrote:
tss_create lets you dynamically create thread local storage.
thread_local is static. Gets resolved at ld time. Doesn't
work too well if you want a per object instance of thread
local storage. Something like that in C++?
Joe Seigh
I figured something out so all good I think.
So basically just declare a thread local array. It will have
fixed size and you will have to manage allocation of array
slots and dtors and stuff. E.g.
thread_local void * x2[20];
Accessing a slot value, if you inline it with a uint64_t
key on x86 will get you something like
movq %fs:x2@tpoff(,%rax,8), %rdx
with %rax containing the index, i.e. the key,
which will beat calling tss_get which calls
pthread_getspecific.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (1 / 9) |
Uptime: | 76:00:43 |
Calls: | 12,949 |
Calls today: | 3 |
Files: | 186,574 |
Messages: | 3,264,533 |