Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #120706
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: thread_local question... |
| Date | 2024-10-11 22:53 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <ved2sr$28p8$2@dont-email.me> (permalink) |
| References | <ve7cj8$2vun0$1@dont-email.me> <ve8f6l$34vt2$1@dont-email.me> <ve98fe$392tv$2@dont-email.me> <vebael$3make$1@dont-email.me> <vebtr6$3p9aj$1@dont-email.me> |
On 10/11/2024 12:21 PM, Chris M. Thomasson wrote:
> On 10/11/2024 6:50 AM, jseigh wrote:
>> 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.
>>>
>>
>> Ok, it looks like they are using libc atexit function (stdlib.h) to
>> invoke tls cleanup on thread exit.
>
> Thanks for all of the info Joe! I have an idea that might allow me to
> get a dtor called from thread_local in my test code. I just need to try
> it. Wrt:
> _________________________________
>
> thread_local ct_per_thread* g_per_thread = nullptr;
>
>
> void
> ct_foo()
> {
> // Okay, what about this shit!
> {
> std::unique_lock<std::mutex> lock(g_per_thread-
> >m_shared.m_cout_lock);
> std::cout << "ct_foo(" << g_per_thread->m_id << ")" << std::endl;
> }
> }
>
>
> void
> ct_thread(
> ct_shared& shared,
> unsigned long id
> ) {
> ct_per_thread self(shared, id);
>
> g_per_thread = &self;
>
> ct_foo();
> }
> _________________________________
>
>
> Well, what if I made self in ct_thread thread_local as well? That should
> call self's dtor deeper down the pipe, so to speak. Humm... It should
> work fine. Then any function that ct_thread calls would be able to
> access self via g_per_thread...
>
> ;^)
Humm... It would still not be "dynamic" like the pthread and/or
tss_create version.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-09 19:02 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-09 19:08 -0700
Re: thread_local question... Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-10-09 19:33 -0700
Re: thread_local question... Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-10-09 19:40 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-09 20:08 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-09 20:19 -0700
Re: thread_local question... jseigh <jseigh_es00@xemaps.com> - 2024-10-10 07:52 -0400
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-10 12:04 -0700
Re: thread_local question... wij <wyniijj5@gmail.com> - 2024-10-11 03:20 +0800
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-20 19:12 -0700
Re: thread_local question... wij <wyniijj5@gmail.com> - 2024-10-21 19:06 +0800
Re: thread_local question... wij <wyniijj5@gmail.com> - 2024-10-21 19:20 +0800
Re: thread_local question... jseigh <jseigh_es00@xemaps.com> - 2024-10-10 15:57 -0400
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-11 13:36 -0700
Re: thread_local question... jseigh <jseigh_es00@xemaps.com> - 2024-10-11 09:50 -0400
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-11 12:21 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-11 22:53 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-11 22:56 -0700
Re: thread_local question... jseigh <jseigh_es00@xemaps.com> - 2024-10-11 17:05 -0400
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-12 13:44 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-12 13:46 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-12 13:29 -0700
Re: thread_local question... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-10-12 13:43 -0700
csiph-web