nit: Added link to `CONTRIBUTING.md` from the README
[nit.git] / lib / jvm.nit
index a9e8920..379e6ec 100644 (file)
@@ -15,7 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Manipulates the Java Virtual Machine
+# Java Virtual Machine services
 #
 # See: http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html
 module jvm is
@@ -183,6 +183,14 @@ extern class JavaVM `{JavaVM *`}
                }
                return env;
        `}
+
+       # Detach the calling thread from this JVM
+       fun detach_current_thread import jni_error `{
+               int res = (*self)->DetachCurrentThread(self);
+               if (res != JNI_OK) {
+                       JavaVM_jni_error(NULL, "Could not detach current thread to Java VM", res);
+               }
+       `}
 end
 
 # Represents a jni JNIEnv, which is a thread in a JavaVM