当前位置: 技术问答>linux和unix
eclipse调试c++ 线程,主线程显示状态stepping????
来源: 互联网 发布时间:2016-05-21
本文导语: eclipse调试c++ 线程,主线程显示状态stepping???? linux 下我开了三个线程,主线程等待三个子线程结束,但三个子线程结束后,主线程不能结束,debug显示stepping,哪位可以解释一下?????? 代码如下: #includ...
eclipse调试c++ 线程,主线程显示状态stepping????
linux 下我开了三个线程,主线程等待三个子线程结束,但三个子线程结束后,主线程不能结束,debug显示stepping,哪位可以解释一下??????
代码如下:
#include"ctypes.h"
#include"cport.h"
#include
#include
using namespace std;
#include
#include
#include
#include
#include
pthread_t id1,id2,id3;
void *write(void *args)
{
cJobqueue *job=(cJobqueue *)args;
for(int i=0;ipost(i);
printf("post id : %d by thread_id : %d n",i,pthread_self());
}
return NULL;
}
void *write2(void *args)
{
cJobqueue *job=(cJobqueue *)args;
for(int i=300;ipost(i);
printf("post id : %d by thread_id : %d n",i,pthread_self());
}
return NULL;
}
void *read(void *args)
{
cJobqueue *job=(cJobqueue *)args;
int i;
while(TRUE)
{
i=job->getmessage()->id;
if(i == 356 )
{
break;
}
printf("get job msg i : %dn",i);
}
return NULL;
}
int main(){
int err;
cJobqueue jobq(400);
err = pthread_create(&id1,NULL,write,(void *)&jobq);
err = pthread_create(&id2,NULL,write2,(void *)&jobq);
err = pthread_create(&id3,NULL,read,(void *)&jobq);
if(err != 0){
printf("can't create thread: %sn",strerror(err));
return 1;
}
pthread_join(id1,NULL);
pthread_join(id2,NULL);
pthread_join(id3,NULL);
printf("main thread:n");
return 0;
}
linux 下我开了三个线程,主线程等待三个子线程结束,但三个子线程结束后,主线程不能结束,debug显示stepping,哪位可以解释一下??????
代码如下:
#include"ctypes.h"
#include"cport.h"
#include
#include
using namespace std;
#include
#include
#include
#include
#include
pthread_t id1,id2,id3;
void *write(void *args)
{
cJobqueue *job=(cJobqueue *)args;
for(int i=0;ipost(i);
printf("post id : %d by thread_id : %d n",i,pthread_self());
}
return NULL;
}
void *write2(void *args)
{
cJobqueue *job=(cJobqueue *)args;
for(int i=300;ipost(i);
printf("post id : %d by thread_id : %d n",i,pthread_self());
}
return NULL;
}
void *read(void *args)
{
cJobqueue *job=(cJobqueue *)args;
int i;
while(TRUE)
{
i=job->getmessage()->id;
if(i == 356 )
{
break;
}
printf("get job msg i : %dn",i);
}
return NULL;
}
int main(){
int err;
cJobqueue jobq(400);
err = pthread_create(&id1,NULL,write,(void *)&jobq);
err = pthread_create(&id2,NULL,write2,(void *)&jobq);
err = pthread_create(&id3,NULL,read,(void *)&jobq);
if(err != 0){
printf("can't create thread: %sn",strerror(err));
return 1;
}
pthread_join(id1,NULL);
pthread_join(id2,NULL);
pthread_join(id3,NULL);
printf("main thread:n");
return 0;
}
|
pthread_join(id1,NULL);
pthread_join(id2,NULL);
pthread_join(id3,NULL);
printf("main thread:n");
return 0;
}
你可以调试一下这后面几条语句,如果执行return 0;后主线程还显示stepping,但证明你的主线程阻塞,
极可能阻塞在cJobqueue的析构上,
pthread_join(id2,NULL);
pthread_join(id3,NULL);
printf("main thread:n");
return 0;
}
你可以调试一下这后面几条语句,如果执行return 0;后主线程还显示stepping,但证明你的主线程阻塞,
极可能阻塞在cJobqueue的析构上,