void
ct_thread(
ct_shared& shared,
unsigned long id
) {
// Well, self should be per thread...
thread_local ct_per_thread self(shared, id);
ct_foo();
}
On 10/09/24 7:02 PM, Chris M. Thomasson wrote:
void
ct_thread(
ct_shared& shared,
unsigned long id
) {
// Well, self should be per thread...
thread_local ct_per_thread self(shared, id);
ct_foo();
}
However, the real question here is: why you are even declaring your
variable as `thread_local`? A regular local variable inside a thread
function is already as "thread local" as it can possibly get. The only
thing that `thread_local` will give you is the retention of the old
value between calls. Do you really need that?
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()?
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.
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.
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.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 59:00:02 |
Calls: | 10,397 |
Calls today: | 5 |
Files: | 14,067 |
Messages: | 6,417,461 |
Posted today: | 1 |