Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spec] {.threadvar.} and destructors #12624

Open
mratsim opened this issue Nov 7, 2019 · 2 comments
Open

[Spec] {.threadvar.} and destructors #12624

mratsim opened this issue Nov 7, 2019 · 2 comments

Comments

@mratsim
Copy link
Collaborator

mratsim commented Nov 7, 2019

As discussed on IRC (https://irclogs.nim-lang.org/07-11-2019.html#18:25:52), the spec doesn't cover if destructors are inserted for thread-local variable before thread destruction.

It should say clearly if they are or if they are not.

@mratsim mratsim changed the title {.threadvar.} and destructors [SPEC] {.threadvar.} and destructors Nov 7, 2019
@mratsim mratsim changed the title [SPEC] {.threadvar.} and destructors [Spec] {.threadvar.} and destructors Nov 7, 2019
@Araq
Copy link
Member

Araq commented Nov 8, 2019

They are not injected but the real question is whether that's really good enough... Likewise, collecting all threadlocal destructors into a single one is not modular and requires a heavier threading implementation than I would like.

We probably need to do the same as: https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables

@timotheecour
Copy link
Member

timotheecour commented Jan 29, 2021

the spec doesn't cover if destructors are inserted for thread-local variable before thread destruction.

IMO we should ensure that destructors are inserted, even if this only holds for C++, and even if that only holds furthermore for >= C++11 (until we implement this for C backend as well or tlsEmulation:off). That's the most sensible behavior for correctnesss / usefulness.

note that now that #16750 was merged, for {.cppNonPod.} importcpp types that have a destructor, a TLS variable (which is now mapped to a C++11 thread_local) will have its C++ destructor called on thread termination; a test still needs to be added to ensure this but this is what I had observed when writing #16750

question

@Araq are nim destructors mapped to a C++ destructor on C++ backend? and does it depend on --gc:arc|default?

if so, then looks like this provides a full solution for C++11 (and we must also ensure that nim destructor for a type Foo has same behavior as {.cppNonPod.}, ie makes a TLS use thread_local even if that type wasn't even importcpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants