On 10/10/24 15:04, Chris M. Thomasson wrote:
On 10/10/2024 4:52 AM, jseigh wrote:
On 10/9/24 22:02, Chris M. Thomasson wrote:
How can I get access to self in my ct_foo() function below? Am I
misusing thread_local here? I want self to be able to be accessible
from any function that my ct_thread() function calls. It feels like I
am doing something wrong here. However, I am getting correct ctor's
and dtor's, I am not sure how to access self from ct_foo() called
from ct_thread()?
std::thread::id id = std::this_thread::get_id();
C tss uses a thread local array I think but I don't know
it gets notification on individual thread exits so it
can run the dtor. C++ has a cvar notify all on thread
exits.
I have a different hack which I won't get around to
until I need it.
I still don't know how C++ calls dtors wrt per-thread objects via thread_local. My hack would be to use tss_create and be done with it.
I got some stack traces from C vs C++ threads (not the main threads
which have identical stack traces).
C
#4 0x00000000004011c6 in test ()
#5 0x00007ff68a489be1 in start_thread (arg=<optimized out>) at pthread_create.c:440
#6 0x00007ff68a50ed40 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
C++
#4 0x00000000004012b6 in test(void*) ()
#5 0x00007fa23f4dbad4 in std::execute_native_thread_routine
(__p=0x173ceb0) at ../../../../../libstdc++-v3/src/c++11/thread.cc:82
#6 0x00007fa23f089d22 in start_thread (arg=<optimized out>) at pthread_create.c:443
#7 0x00007fa23f10ed40 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
So the tss uses the pthread stuff and C++ uses std::execute_native_thread_routine on top of that.
C and C++ main
#4 0x0000000000401056 in main ()
#5 0x00007fae98e295d0 in __libc_start_call_main
(main=main@entry=0x401050 <main>, argc=argc@entry=1,
argv=argv@entry=0x7ffff84f1d18) at ../sysdeps/nptl/libc_start_call_main.h:58
#6 0x00007fae98e29680 in __libc_start_main_impl (main=0x401050 <main>,
argc=1, argv=0x7ffff84f1d18, init=<optimized out>,
fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7ffff84f1d08) at ../csu/libc-start.c:389
#7 0x0000000000401085 in _start ()
No extra c++ magic sauce there that I can see.
I wonder how many people realize a thread's entry point isn't
necessarily the first thing that's called.
Joe Seigh
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)