NDK / JNI: defining the current topic

In the JNI native method, is there a way to find out the identifier of the current thread without calling Java back? A theme-based repository will also work.

EDIT: pthread.h is present in the include NDK folder ... Does anyone know if Java POSIX threads are consistent in the NDK implementation?

+6
source share
1 answer

Which identifier are you interested in? Dalba Stream Dalvik includes the following:

  "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" is the identifier of the virtual machine. "handle" is pthread_t. "sysTid" is the result of gettid () (Linux process identifier).

The libcore thread id (derived from java.lang.Thread.getId ()) is not displayed.

(You can get the above value with “adb shell kill -3.” The output goes to the shared file defined by the dalvik.vm.stack-trace-file property - usually /data/anr/traces.txt, but it depends on the device. )

EDIT: Each Dalvik VM thread is pthread Linux. The gettid () script will give you a unique identifier for each thread. Alternatively, you can add authentication information to TLS in java.lang.Thread or pthread_key.

+5
source

Source: https://habr.com/ru/post/886420/


All Articles