Sequencing of DetachCurrentThread in multithreaded C++ program

Hi,

in my C++ program, (MVC++ on XP, using Java 1.5.0_06) the JVM throws a great big hissy fit if threads do not attach and detach in a strict queue like order. For example, the program crashes at *** in the following sequence:

Thread 1: attach to JVM

Thread 2: attach to JVM

Thread 2: detach from JVM ***

If Thread 1 detaches from the JVM before Thread 2 detaches, then everything is fine. I found a similar issue, but no answers, in

http://forum.java.sun.com/thread.jspa?forumID=52&threadID=754378

Is this defined or well known behavior ?

Thanks for any info.

[622 byte] By [Ilovua] at [2007-11-26 14:10:20]
# 1
> > Is this defined or well known behavior ? I would guess (strong guess) that something is wrong with your code.Obviously it would be very easy to create a very minimal example that demonstrates this if it is a problem with the VM code.
jschella at 2007-7-8 1:57:51 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

There's no reason it should crash. Threads are free to attach and detach any time they want. It's possible you're doing something strange with JNI that works until the other thread exits. One thing you need to be careful about is passing local refs between threads since that will work ok until it doesn't. Try running with -Xcheck:jni.

Do you have an hs_err_pid log from the crash?

tom

neverevera at 2007-7-8 1:57:51 > top of Java-index,Java HotSpot Virtual Machine,Specifications...