-
Notifications
You must be signed in to change notification settings - Fork 488
Provide a method to run functions on JVM thread #398
Conversation
I've tested this and confirm it works my side. However I don't personally like the extra code clutter to use this, nor the overhead of constantly attaching/detaching. |
std::abort(); | ||
} | ||
f(); | ||
if (attached) g_cachedJVM->DetachCurrentThread(); |
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.
Please make the if one line if's consistent with the rest, just have a {} for if's scope like the majority.
- if (attached) g_cachedJVM->DetachCurrentThread();
+ if (attached) {
+ g_cachedJVM->DetachCurrentThread();
+ }
std::abort(); | ||
} | ||
auto result = f(); | ||
if (attached) g_cachedJVM->DetachCurrentThread(); |
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.
Please make the if one line if's consistent with the rest, just have a {} for if's scope like the majority.
- if (attached) g_cachedJVM->DetachCurrentThread();
+ if (attached) {
+ g_cachedJVM->DetachCurrentThread();
+ }
Just a note that #405 has been merged now, I'm not sure if there is a good reason to have more than one way to do this or not. |
That's fair enough. I just pointed out because I have seen some pretty tedious bugs introduced because of the missing braces after an if. |
#405 provided an alternative option to this. This repo isn't going to be adding any new features so I'm putting this PR on hold. |
This is an attempt to provide a way for C++-created threads to call into Java without risking a memory leak, as requested in #176 . The basic idea is this:
There are two functions because I'm not skilled enough with lambdas to make one function that will accept any kind of lambda.