NDK / JNI:识别当前线程 [英] NDK/JNI: identifying current thread

查看:1365
本文介绍了NDK / JNI:识别当前线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个JNI本地方法,有没有办法知道当前线程的ID,而无需调用Java回来了?线程本地存储也将工作。

In a JNI native method, is there a way to know the ID of the current thread without calling Java back? Thread-local storage would also work.

编辑:pthreads.h中是present在NDK包括文件夹...有谁知道,如果Java线程的NDK实施符合POSIX的人

pthread.h is present in the NDK include folder... Does anyone know if Java threads correspond to POSIX ones in the NDK implementation?

推荐答案

哪个ID是你感兴趣的?一个Dalvik的线程转储包含这样的:

Which ID are you interested in? A Dalvik thread dump includes this:

"main" prio=5 tid=1 TIMED_WAIT
  | group="main" sCount=1 dsCount=0 obj=0x40017730 self=0x12798
  | sysTid=3167 nice=0 sched=0/0 cgrp=default handle=-2146114456
  | schedstat=( 358850000 275073000 869 ) utm=23 stm=12 core=0

TID是虚拟机的ID。 处理是的pthread_t。 sysTid是gettid()(Linux的进程ID)的结果。

"tid" is the VM's ID. "handle" is the pthread_t. "sysTid" is the result of gettid() (the Linux process ID).

的libcore线程ID(从java.lang.Thread.getId()获得)中未示出

The libcore thread ID (obtained from java.lang.Thread.getId()) is not shown.

(你可以得到上面亚行外壳杀-3的输出进入一个共同文件,由dalvik.vm.stack追踪文件属性定义的 - 通常/data/anr/traces.txt ,但它因器件而异。)

(You can obtain the above with "adb shell kill -3 ". The output goes to a common file, defined by the dalvik.vm.stack-trace-file property -- usually /data/anr/traces.txt, but it varies by device.)

编辑:每一个Dalvik虚拟机线程是一个Linux的pthread。该gettid()系统调用会给你的每个线程一个唯一的ID。此外,您还可以在java.lang.Thread中或pthread_key添加识别信息TLS。

Every Dalvik VM thread is a Linux pthread. The gettid() syscall will give you a unique ID for each thread. Also, you can add identifying information to TLS in java.lang.Thread or pthread_key.

这篇关于NDK / JNI:识别当前线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆