Android JNI 启动线程,并设置线程名称
#include <Jni.h>
#include <string.h>
#include <stdint.h>
#include "android/log.h"
#include<unistd.h>
#include<pthread.h>
void *thread_fun(void* arg)
{
int i =0;
for(i=0;i<10000;i++)
{
__android_log_print(ANDROID_LOG_INFO, TAG, "thread_fun i=%d",i);
}
return NULL;
}
void TestThread()
{
int i=0;
pthread_t pt;
int rc;
char thread_name[NAMELEN];
pthread_create(&pt, NULL, &thread_fun, (void *)i);
memset(&thread_name,0,NAMELEN);
thread_name[0]='w';
thread_name[1]='w';
thread_name[2]='w';
__android_log_print(ANDROID_LOG_INFO, TAG, "thread_name =%s",thread_name);
//pthread_setname_np(pt, "new thread");
pthread_setname_np(pt, thread_name);
}
posted on 2017-03-21 19:56 kenny.wmh 阅读(2142) 评论(0) 编辑 收藏 举报