Skip to content

Thread safety considerations in C code #788

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

Closed
mahesh-hegde opened this issue Aug 18, 2022 · 1 comment
Closed

Thread safety considerations in C code #788

mahesh-hegde opened this issue Aug 18, 2022 · 1 comment

Comments

@mahesh-hegde
Copy link
Contributor

Non-exhaustive list of places where race conditions may occur

  • Class and method references are global variables in generated C bindings. These variables are checked during a call and looked up in JNI if they are null. Method/Field IDs do not seem to be problematic since they are not themselves reclaimable, and merely associated with the class reference. The class reference however may leak if 2 threads try to use an un-initialized class concurrently.

Is this a concern and does this operation (check-and-load-if-null) have to be wrapped in a mutex? I think something like double-checked locking can be used to retain a faster path in loaded case.

  • Spawn checks if the global JniContext is populated with non-null JVM reference. There's a chance if 2 spawns are called simultaneously. But spawn is supposed to be called at the beginning of the program. I don't think this is a significant concern.
@mahesh-hegde
Copy link
Contributor Author

This should be a non-issue if #772 is implemented.

@HosseinYousefi HosseinYousefi transferred this issue from dart-archive/jnigen Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant