在system.log中,我可以看到我的进程:
thread 515376 caught burning CPU! It used more than 50% CPU
我使用多个线程,所以我尝试在线程使用的可运行方法中打印线程 ID,例如:
void* runnable1(void* ptr)
{
pthread_t tid = pthread_self();
printf("HELLO from thread runnable1 with id : %ld\n", tid);
...
}
但是,我得到的 ID 如下:
HELLO from thread runnable1 with id : 4488212480
这与 system.log 中的非常不同。
问题是如何按照 system.log 中显示的方式获取线程 ID?
尝试:
uint64_t tid;
pthread_threadid_np(NULL, &tid);
printf("HELLO from thread runnable1 with id : %ld\n", tid);