classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GTK peer switching JNIEnv *?


From: Archie Cobbs
Subject: Re: GTK peer switching JNIEnv *?
Date: Fri, 14 Jan 2005 09:14:13 -0600
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129

Robert Lougher wrote:
It would be an interesting question to ask if JNI code
should expect the JNIEnv* to be different for different threads. Opinions?

Stop the nonsense! :-)

The idea that there is anything other than a 1:1 pairing between
threads and JNIEnv * pointers is crazy^H^H^H^H^Hincorrect. Quoting:

  http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/design.html

The JNI interface pointer is only valid in the current thread. A native method, therefore, must not pass the interface pointer from one thread to another. A VM implementing the JNI may allocate and store thread-local data in the area pointed to by the JNI interface pointer.

Native methods receive the JNI interface pointer as an argument. The VM is guaranteed to pass the same interface pointer to a native method when it makes multiple calls to the native method from the same Java thread. However, a native method can be called from different Java threads, and therefore may receive different JNI interface pointers.

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]