safe to invoke AttachCurrentThread() multiple times from same native thread?

2,179 views
Skip to first unread message

Lee Leclair

unread,
Jul 14, 2010, 10:23:46 AM7/14/10
to android-ndk
Is it safe to invoke AttachCurrentThread() multiple times from the
same native thread? In other words, after the first invocation, will
subsequent invocations be no-opts or will they be problematic.

Angus Lees

unread,
Jul 14, 2010, 10:32:22 AM7/14/10
to andro...@googlegroups.com
The docs for AttachCurrentThread say: (http://java.sun.com/docs/books/jni/html/functions.html)

Trying to attach a thread that is already attached simply sets the value pointed to by penv to the JNIEnv of the current thread.

 - Gus



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


alan

unread,
Jul 16, 2010, 11:36:08 AM7/16/10
to android-ndk
Calling attach multiple times doesnt directly cause problems but if
you call detach then the thread will immediately detach. For example
this code will not work correctly:

void f1()
{
AttachCurrentThread();
//call jni function
DetachCurrentThread();
}

void f2()
{
AttachCurrentThread();
//call jni function
f1();
//calling jni functions here will not work
DetachCurrentThread();
}

On Jul 14, 3:32 pm, Angus Lees <al...@google.com> wrote:
> The docs for AttachCurrentThread say: (http://java.sun.com/docs/books/jni/html/functions.html)
>
> Trying to attach a thread that is already attached simply sets the value
>
> > pointed to by penv to the JNIEnv of the current thread.
>
>  - Gus
>
> On Thu, Jul 15, 2010 at 00:23, Lee Leclair <zer0stimu...@gmail.com> wrote:
> > Is it safe to invoke AttachCurrentThread() multiple times from the
> > same native thread? In other words, after the first invocation, will
> > subsequent invocations be no-opts or will they be problematic.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages