jni thread 退出异常 , native thread exited without detaching
线程退出时控制台出现以下异常 :
thread exiting, not yet detached (count=0) thread exiting, not yet detached (count=1) native thread exited without detaching
代码中已经设置分离线程模式. 请指教
pthread_attr_t pulseTattr; pthread_t pulseThread; memset(&pulseThread, 0, sizeof(pthread_t)); memset(&pulseTattr, 0, sizeof(pthread_attr_t)); int err; err = pthread_attr_init (&pulseTattr);
err = pthread_attr_setdetachstate (&pulseTattr,PTHREAD_CREATE_DETACHED);
err = pthread_create(&pulseThread,&pulseTattr,sendPulsePackThread,&sk); if(err != 0) { __android_log_write(ANDROID_LOG_ERROR,"Tag","pthread_create fail \n"); } else { __android_log_write(ANDROID_LOG_ERROR,"Tag","pthread_create succ \n"); }
void *sendPulsePackThread(void *args) { T_Socket *s = (T_Socket*)args; DATAHEAD dataHead; dataHead.HeadFlag = '1111'; dataHead.lLen = 0; while(pulseOpen==1) { sleep(10); if(SendData(s->socket,(char*)&dataHead,sizeof(DATAHEAD),10) == SOCKET_ERROR) { __android_log_write(ANDROID_LOG_ERROR,"Tag","sendPulsePackThread send fail \n"); } __android_log_write(ANDROID_LOG_ERROR,"Tag","sendPulsePackThread mark \n"); } __android_log_print(ANDROID_LOG_ERROR,"Tag", " pulseOpen :%d \n", pulseOpen);
__android_log_write(ANDROID_LOG_ERROR,"Tag","sendPulsePackThread mark \n"); // pthread_detach(pthread_self());
__android_log_write(ANDROID_LOG_ERROR,"Tag","sendPulsePackThread exit \n");
pthread_exit((void *)0); } 说的应该是这个 DetachCurrentThread
|