-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix #16752: threadvar now works with importcpp types; osx now uses native TLS (--tlsEmulation:off
), which can be orders of magnitude faster
#16750
Conversation
d22a0bc
to
40c8f57
Compare
--tlsEmulation:off
), which can be orders of magnitude faster
40c8f57
to
567d2d8
Compare
--tlsEmulation:off
), which can be orders of magnitude faster--tlsEmulation:off
), which can be orders of magnitude faster
--tlsEmulation:off
), which can be orders of magnitude faster--tlsEmulation:off
), which can be orders of magnitude faster
--tlsEmulation:off
), which can be orders of magnitude faster--tlsEmulation:off
), which can be orders of magnitude faster
--tlsEmulation:off
), which can be orders of magnitude faster--tlsEmulation:off
), which can be orders of magnitude faster
0e7a3d2
to
6303d3c
Compare
Linked to #12624 Also linked to Weave issue mratsim/weave#61 (comment) Note that on Mac, tlsEmulation was on by default for iPhone support which lagged a bit behind MacOSX. |
Another issue with tlsEmulation on Windows, Ctrl-C will crash your program #4057. |
6303d3c
to
7fc37e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ping @Araq |
Instead of yet another pragma, we should IMHO mark non-pod C++ types with an importc'ed destructor or similar. |
that won't work, struct Foo2 {
Foo2() { }
};
int main() {
static __thread Foo2 a2;
return 0;
}
I don't see how this can work either. # case 1: works
struct Base {
};
# case 2: doesn't work
struct Base {
Base() { }
};
# case 3: doesn't work
struct Base {
Base(int n) { }
};
# case 4: works
struct Base {
Base() = default;
Base(int n) { } # with or without this
};
# rest of code:
struct Derived : public Base {
};
void bar() {
static __thread Derived a2;
}
int main (int argc, char *argv[]) {
bar();
return 0;
} As you can see the determination of whether to use |
Ok, I'm convinced. But can we move the FFI pragmas out of the manual to an "appendix"? These things shouldn't be part of the language "spec". |
I'm happy to do that in a followup PR, which would move all ffi pragmas (including nodecl, incompleteStruct etc) into lib/ffi.rst; this is out of scope for this PR though. |
… uses native TLS (`--tlsEmulation:off`), which can be orders of magnitude faster (nim-lang#16750) * osx now uses native TLS, which can be orders of magnitude faster * add {.cppNonPod.} * improve test * changelog, docs, disable part of windows test
{.cppNonPod.}
specifies a importcpp type is a non-POD, and shall usethread_local
instead of__thread
for{.threadvar.}
variableslinks
https://en.wikipedia.org/wiki/Thread-local_storage#C.2B.2B
__thread vs thread_local: https://stackoverflow.com/questions/12049095/c11-nontrivial-thread-local-static-variable
AFAIK nim uses POD types in cgen code, even for types with destructors, and even for c++
freebsd, openbsd, netbsd
I didn't change the behavior here, but see: #15066 (comment) and #15493
note regarding
cppNonPod
I used
pod
for simplicity in the pragma name even though__is_pod
trait will be deprecated (see https://stackoverflow.com/a/48225882/1426932):this pragma is user defined anyways, and the compiler will error if that pragma is missing, resulting in
__thread
being used on a variable of a type that contains non-trivial destructor or if type has a constructor and cgen callsvar a: Foo
.So in the end it works as intended.
note regarding
thread_local
__has_feature(cxx_thread_local)
conditionallythread_local
is supported on OSX since xcode 8, released in 2016future work
{.cppNonPod.}
, eg thread safe static initialization:instead of
Error: a thread var cannot be initialized explicitly; this would only run for the main thread
we could allow:see how to fix the disabled part of ttlsemulation.nim that fails for windows with
cpp --threads --tlsEmulation:off
address this: fix #16752: threadvar now works with importcpp types; osx now uses native TLS (
--tlsEmulation:off
), which can be orders of magnitude faster #16750 (comment)