Chinaunix

标题: linux c++ 线程退出时的问题 [打印本页]

作者: jiangpingzhan    时间: 2011-01-27 09:41
标题: linux c++ 线程退出时的问题
打印异常.

thread exiting, not yet detached (count=0)
thread exiting, not yet detached (count=1)


native thread exited without detaching  


在线程内已经添加退出代码

        pthread_detach(pthread_self());


        pthread_exit((void *)0);


麻烦各位指教
作者: wb112200    时间: 2011-01-27 09:49
把代码贴出来看看吧
作者: jiangpingzhan    时间: 2011-01-27 10:50
void *sendPulsePackThread(void *args)
{
        T_Socket  *s = (T_Socket*)args;
        DATAHEAD dataHead;
        dataHead.HeadFlag = '1111';
        dataHead.lLen = 0;
        while(streamOpen==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");
        pthread_detach(pthread_self());
        __android_log_write(ANDROID_LOG_ERROR,"Tag","sendPulsePackThread   exit    \n");
        pthread_exit((void *)0);
}
作者: rain_fish    时间: 2011-01-27 13:11
回复 3# jiangpingzhan


    哥们儿你贴的代码是神马?
作者: jiangpingzhan    时间: 2011-01-27 14:49
回复  jiangpingzhan


    哥们儿你贴的代码是神马?
rain_fish 发表于 2011-01-27 13:11



    linux c++ 的线程代码
作者: 独臂剑客    时间: 2011-01-27 23:53
你应该是初始化设置了属性 PTHREAD_CREATE_DETACHED
如果设置了些属性,就不要使用pthread_detach()和pthread_join,否则就会异常
作者: jiangpingzhan    时间: 2011-03-02 15:12
这个问题还没有解决 . .

情况是这样的

在a 线程   启动B 线程


结束a  \ b  线程


出现上面的异常




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2